package com.util;

import java.time.Duration;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;
import java.util.TimeZone;

import org.apache.commons.lang3.StringUtils;

import com.Dto.OldDataDto;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

public class FrameUtil {
	
	public static String loginUrl= "http://192.168.1.100/logincheck.rsp?type=1";
	public static String macUrl= "http://192.168.1.100/getparameter.json";
	public static String versionUrl= "http://192.168.1.100/device.rsp";
	public static String userName= "admin";
	public static String passWord= "";

	public static byte[] addBytes(byte[] data1, byte[] data2) {
		if(data2==null) {
			return data1;
		}
        byte[] data3 = new byte[data1.length + data2.length];
        System.arraycopy(data1, 0, data3, 0, data1.length);
        System.arraycopy(data2, 0, data3, data1.length, data2.length);
        return data3;
    }
    
    /**
     * Hex字符串转byte
     * @param inHex 待转换的Hex字符串
     * @return 转换后的byte
     */
    public static byte hexToByte(String inHex) {
        return (byte) Integer.parseInt(inHex, 16);
    }

    /**
     * hex字符串转byte数组
     * @param inHex 待转换的Hex字符串
     * @return 转换后的byte数组结果
     */
    public static byte[] hexToByteArray(String inHex) {
        int hexlen = inHex.length();
        byte[] result;
        if (hexlen % 2 == 1) {
            // 奇数
            hexlen++;
            result = new byte[(hexlen / 2)];
            inHex = "0" + inHex;
        } else {
            // 偶数
            result = new byte[(hexlen / 2)];
        }
        int j = 0;
        for (int i = 0; i < hexlen; i += 2) {
            result[j] = hexToByte(inHex.substring(i, i + 2));
            j++;
        }
        return result;
    }

    /**
     * 数组转换成十六进制字符串
     * @param byte[]
     * @return HexString
     */
    public static final String bytesToHexString(byte[] bArray) {
        StringBuffer sb = new StringBuffer(bArray.length);
        String sTemp;
        for (int i = 0; i < bArray.length; i++) {
            sTemp = Integer.toHexString(0xFF & bArray[i]);
            if (sTemp.length() < 2)
                sb.append(0);
            sb.append(sTemp.toUpperCase());
        }
        return sb.toString();
    }
    
    //获取校验值
    public static byte checkData(byte[] data) {
    	byte temp = 0x00; //校验值
        for(int i = 0;i<data.length;i++){ //异或
            temp ^= data[i];
        }
		return temp;
	}
    
    //根据指令生成frameDto
    public static FrameDto createData(String item) throws Exception {
    	byte order = FrameUtil.getOrder(item);
		FrameDto frameDto = new FrameDto();
		byte[] dataSize=new byte[2];
		dataSize[0]=0x00;
		dataSize[1]=0x00;
		frameDto.setDataSize(dataSize);
		frameDto.setOrder(order);
		frameDto.setData(null);
		byte[] bytes= new byte[2];
		bytes[0]=frameDto.getAddress();
		bytes[1]=frameDto.getOrder();
		bytes = FrameUtil.addBytes(bytes, dataSize);
		byte checkData = FrameUtil.checkData(bytes);
		frameDto.setCheck(checkData);
		return frameDto;
	}
    
    
    //整理数据
    public static FrameDto fillData(byte[] data) {
    	int size=data.length;
    	if(size<7) {
    		return null;
    	}
    	FrameDto frameDto = new FrameDto();
    	
    	
    	//数据长度
    	byte[] finalDataSize=new byte[2];
    	finalDataSize[0]=data[3];
    	finalDataSize[1]=data[4];
    	try {
			frameDto.setDataSize(finalDataSize);
		} catch (Exception e) {
			return null;
		}
    	
    	
    	//数据
    	byte[]  datas=new byte[size-7];
    	for (int i = 5; i < size-2; i++) {
			datas[i-5]=data[i];
		}
    	frameDto.setData(datas);
    	
    	//数据校验
    	byte[]  checkData=new byte[size-3];
    	for (int i = 1; i < size-2; i++) {
    		checkData[i-1]=data[i];
		}
    	byte checkData2 = checkData(checkData);
    	frameDto.setCheck(checkData2);
    	
    	
    	//指令
    	frameDto.setOrder(data[2]);
    	
		return frameDto;
	}
    
    /**
     * Ascii码转String
     * @param result2
     * @return
     */
    public static String AsciiToString(byte[] result2) {
        StringBuilder sbu = new StringBuilder();
        for (byte b : result2) {
            if (0 == b) {
                break;
            }
            sbu.append((char) Integer.parseInt(String.valueOf(b)));
        }
        return sbu.toString();
    }
    /**
     * Ascii转byte
     * @param value
     * @return
     * @throws Exception 
     */
    public static byte[] stringToAscii(String value) throws Exception  
	{  
    	  
        char[] chars = value.toCharArray();
        byte[] data=new byte[chars.length];
        for (int i = 0; i < chars.length; i++) {  
            data[i] =(byte)chars[i];  
        }  
       
        return data;
	     
	}
    /**
     * 处理04：mac写入
     * @param macAddress
     * @return
     * @throws Exception
     */
    public static FrameDto creatDto_04(byte[] macAddress) throws Exception {
    	FrameDto frameDto=new FrameDto();
    	frameDto.setData(macAddress);
		frameDto.setDataSize(new byte[] {0x00,0x06});
		frameDto.setOrder(FrameUtil.OrderTye.MAC_WRITE);
		byte[] addBytes = FrameUtil.addBytes(new byte[] {frameDto.getAddress()},new byte[]{frameDto.getOrder()});
		addBytes = FrameUtil.addBytes(addBytes, frameDto.getDataSize());
		addBytes = FrameUtil.addBytes(addBytes, frameDto.getData());
		byte checkData = FrameUtil.checkData(addBytes);
		frameDto.setCheck(checkData);
		return frameDto;
	}
    public static FrameDto creatDto_25(String data) throws Exception {
    	FrameDto frameDto=new FrameDto();
		byte[] stringToAscii = FrameUtil.stringToAscii(data);
		byte[] realData=new byte[32];
		for(int i=0;i<32;i++) {
			if(i<stringToAscii.length) {
				realData[i]=stringToAscii[i];
			}else {
				realData[i]=0x00;
			}
		}
		frameDto.setData(realData);
		frameDto.setOrder(OrderTye.SN_WRITE);
		frameDto.setDataSize(new byte[] {0x00,0x20}); //固定32位
		byte[] addBytes = FrameUtil.addBytes(new byte[] {frameDto.getAddress()},new byte[]{frameDto.getOrder()});
		addBytes = FrameUtil.addBytes(addBytes, frameDto.getDataSize());
		addBytes = FrameUtil.addBytes(addBytes, frameDto.getData());
		byte checkData = FrameUtil.checkData(addBytes);
		frameDto.setCheck(checkData);
		return frameDto;
	}
    
     public static FrameDto creatDto_1C(String phone) throws Exception {
    	 FrameDto frameDto=new FrameDto();
    	 byte[] data= {};
    	 for (int i = 0; i < phone.length(); i++) {
			byte[] item = FrameUtil.hexStringToBytes("3"+phone.charAt(i));
			data=FrameUtil.addBytes(data, item);
		}
    	frameDto.setOrder(OrderTye.PHONE_WRITE);
    	String length=Integer.toHexString(phone.length());
    	if(length.length()%2==1) {
    		length="0"+length;
    	}
    	byte[] lenByte = FrameUtil.hexStringToBytes(length);
    	
    	if(lenByte.length==1) {
    		frameDto.setDataSize(new byte[] {0x00,lenByte[0]});
    	}else if(lenByte.length==2){
    		frameDto.setDataSize(new byte[] {lenByte[0],lenByte[1]});
    	}else {
    		throw new Exception("扫描输入数据"+phone+"长度不正确");
    	}
    	
    	frameDto.setData(data);
    	byte[] addBytes = FrameUtil.addBytes(new byte[] {frameDto.getAddress()},new byte[]{frameDto.getOrder()});
		addBytes = FrameUtil.addBytes(addBytes, frameDto.getDataSize());
		addBytes = FrameUtil.addBytes(addBytes, frameDto.getData());
		byte checkData = FrameUtil.checkData(addBytes);
		frameDto.setCheck(checkData);
    	return frameDto;
	}
     
     public static FrameDto creatDto_27(String res) throws Exception {
    	 FrameDto frameDto=new FrameDto();
    	 frameDto.setOrder(OrderTye.TERMINAL_ID);
    	 byte[] data = FrameUtil.stringToAscii(res);
    	 frameDto.setData(data);
    	 int dataLength = data.length;

    	 String length=Integer.toHexString(dataLength);
    	 
     	 if(length.length()%2==1) {
     		length="0"+length;
     	 }
     	 byte[] lenByte = FrameUtil.hexStringToBytes(length);
     	
     	 if(lenByte.length==1) {
     		frameDto.setDataSize(new byte[] {0x00,lenByte[0]});
     	 }else if(lenByte.length==2){
     		frameDto.setDataSize(new byte[] {lenByte[0],lenByte[1]});
     	 }else {
     		throw new Exception("扫描输入数据"+res+"长度不正确");
     	 }
     	 byte[] addBytes = FrameUtil.addBytes(new byte[] {frameDto.getAddress()},new byte[]{frameDto.getOrder()});
		 addBytes = FrameUtil.addBytes(addBytes, frameDto.getDataSize());
		 addBytes = FrameUtil.addBytes(addBytes, frameDto.getData());
		 byte checkData = FrameUtil.checkData(addBytes);
		 frameDto.setCheck(checkData);
     	 
    	 return frameDto;
     }
     
     /**
      * 
      * @param inputData
      * @return
      * @throws Exception
      */
     public static FrameDto creatDto_AsciiInput(String inputData,byte order) throws Exception {
    	FrameDto frameDto=new FrameDto();
    	frameDto.setOrder(order);
    	byte[] toAscii = FrameUtil.stringToAscii(inputData);
    	frameDto.setData(toAscii);
    	String length=Integer.toHexString(toAscii.length);
    	if(length.length()%2==1) {
    		length="0"+length;
    	}
    	byte[] lenByte = FrameUtil.hexStringToBytes(length);
    	if(lenByte.length==1) {
     		frameDto.setDataSize(new byte[] {0x00,lenByte[0]});
     	}else if(lenByte.length==2){
     		frameDto.setDataSize(lenByte);
     	}else {
     		throw new Exception("扫描输入数据"+inputData+"长度不正确");
     	}
    	byte[] addBytes = FrameUtil.addBytes(new byte[] {frameDto.getAddress()},new byte[]{frameDto.getOrder()});
    	addBytes = FrameUtil.addBytes(addBytes, frameDto.getDataSize());
		addBytes = FrameUtil.addBytes(addBytes, frameDto.getData());
		byte checkData = FrameUtil.checkData(addBytes);
		frameDto.setCheck(checkData);
    	return frameDto;
	}
     /**
      * for-->创建机型配置类
      * @param type
      * @return
      * @throws Exception
      */
     public static FrameDto creatDto_0D(String type) throws Exception {
    	 FrameDto frameDto=new FrameDto();
    	 Integer parseInt = Integer.parseInt(type);
    	 if(parseInt!=null&&parseInt>999999999) {
    		 throw new Exception("扫描输入数据"+type+"长度不正确");
    	 }else {
    		 byte[] toBytes = FrameUtil.hexStringToBytes(String.valueOf(type));
    		 byte[] data=new byte[] {0x00,0x00,0x00,toBytes[0]};
    		 frameDto.setDataSize(new byte[]{0x00,0x04});
    		 frameDto.setOrder(FrameUtil.OrderTye.MODEL_SET);
    		 frameDto.setData(data);
    		 byte[] addBytes = FrameUtil.addBytes(new byte[] {frameDto.getAddress()},new byte[]{frameDto.getOrder()});
    		 addBytes = FrameUtil.addBytes(addBytes, frameDto.getDataSize());
    		 addBytes = FrameUtil.addBytes(addBytes, frameDto.getData());
    		 byte checkData = FrameUtil.checkData(addBytes);
    		 frameDto.setCheck(checkData);
    	 }
    	 return frameDto;
     }
    /**
     * 将frameDto转化成16进制byte数组，即转为发送给设备的数据
     * @param frameDto
     * @return
     * @throws Exception 
     */
    public static byte[] toPostData(FrameDto frameDto) throws Exception {
    	//开始转义
    	
    	byte[] data = frameDto.getData();
    	if(data!=null&&data.length>0) {
    		String dataString = FrameUtil.bytesToHexString(data).replaceAll("7D", "7D03").replaceAll("7E", "7D01").replaceAll("7F", "7D02"); //转义操作;
    		frameDto.setData(FrameUtil.hexStringToBytes(dataString));
    	}
    	
    	
    	
		byte[] bytes=new byte[3];
		bytes[0]=frameDto.getHead();
		bytes[1]=frameDto.getAddress();
		bytes[2]=frameDto.getOrder();
		
		String dataSize = FrameUtil.bytesToHexString(frameDto.getDataSize()).replaceAll("7D", "7D03").replaceAll("7E", "7D01").replaceAll("7F", "7D02"); //转义操作;
		byte[] dataSizebyte = FrameUtil.hexStringToBytes(dataSize);
		
		String check = FrameUtil.bytesToHexString(new byte[] {frameDto.getCheck()}).replaceAll("7D", "7D03").replaceAll("7E", "7D01").replaceAll("7F", "7D02"); //转义操作;
		byte[] checkByte = FrameUtil.hexStringToBytes(check);
		
		byte[] lasts=new byte[1];
		lasts[0]=frameDto.getLast();
		
		byte[] bytes2 = FrameUtil.addBytes(bytes, dataSizebyte);
		byte[] bytes3 = FrameUtil.addBytes(bytes2, frameDto.getData());
		byte[] bytes4 = FrameUtil.addBytes(bytes3, checkByte);
		byte[] finalData = FrameUtil.addBytes(bytes4, lasts);
		return finalData;
	}
    
    /**
     * 将frameDto转化成字符串
     * @param frameDto
     * @return
     * @throws Exception 
     */
    public static String toPostDataString(FrameDto frameDto) throws Exception {
		byte[] postData = FrameUtil.toPostData(frameDto);
		return FrameUtil.bytesToHexString(postData);
	}
    
    /**
     * 获取指令
     * @param item
     * @return
     */
    public static byte getOrder(String item) {
    	String orderString=StringUtils.lowerCase(item);
    	byte order = 0x00;
    	switch (orderString) {
		case "order_01":
			order=OrderTye.TIME_CHECK;
			break;
		case "order_02":
			order=OrderTye.VERSION_GET;
			break;
		case "order_03":
			order=OrderTye.MAC_GET;
			break;
		case "order_04":
			order=OrderTye.MAC_WRITE;
			break;
		case "order_05":
			order=OrderTye.MEMORY_GET;
			break;
		case "order_06":
			order=OrderTye.MODEL_3G1_GET;
			break;
		case "order_07":
			order=OrderTye.WIFI_GET;
			break;
		case "order_08":
			order=OrderTye.GPS_GET;
			break;
		case "order_09":
			order=OrderTye.PARAMS_EXPORT;
			break;
		case "order_0a":
			order=OrderTye.PARAMS_IMPORT;
			break;
		case "order_0b":
			order=OrderTye.DSM_RESET;
			break;
		case "order_0c":
			order=OrderTye.TEMPERATURE_GET;
			break;
		case "order_0d":
			order=OrderTye.MODEL_SET;
			break;
		case "order_0e":
			order=OrderTye.MICROCHIP_NO_GET;
			break;
		case "order_0f":
			order=OrderTye.AREA_VERSION_CHECK;
			break;
		case "order_10":
			order=OrderTye.AREA_MESSAGE_IMPORT;
			break;
		case "order_11":
			order=OrderTye.CODE_MESSAGE_GET;
			break;
		case "order_12":
			order=OrderTye.MODEL_3G2_GET;
			break;
		case "order_13":
			order=OrderTye.TIME_SET;
			break;
		case "order_14":
			order=OrderTye.FORMAT_DATA;
			break;
		case "order_15":
			order=OrderTye.ACC_STATUS_SEARCH;
			break;
		case "order_16":
			order=OrderTye.VOLTAGE_SEARCH;
			break;
		case "order_17":
			order=OrderTye.RESTART_MACHINE;
			break;
		case "order_18":
			order=OrderTye.SOUND_GET;
			break;
		case "order_19":
			order=OrderTye.SOUND_PLAY;
			break;
		case "order_1a":
			order=OrderTye.SENSOR_INPUT_STATUS_GET;
			break;
		case "order_1b":
			order=OrderTye.SENSOR_OUTPUT_CONTROL;
			break;
		case "order_1c":
			order=OrderTye.PHONE_WRITE;
			break;
		case "order_1d":
			order=OrderTye.LICENCE_CHECK;
			break;
		case "order_1e":
			order=OrderTye.LICENCE_CHECK_GET;
			break;
		case "order_1f":
			order=OrderTye.COM_TEST;
			break;
		case "order_20":
			order=OrderTye.SIX_AXIS_TEST;
			break;
		case "order_21":
			order=OrderTye.PILSE_TEST;
			break;
		case "order_22":
			order=OrderTye.HARD_DISK_LOCK;
			break;
		case "order_23":
			order=OrderTye.CAN1_TEST;
			break;
		case "order_24":
			order=OrderTye.CAN2_TEST;
			break;
		case "order_25":
			order=OrderTye.SN_WRITE;
			break;
		case "order_26":
			order=OrderTye.CHILD_MODEL_SEARCH;
			break;
		case "order_27":
			order=OrderTye.TERMINAL_ID;
			break;
		case "order_2b":
			order=OrderTye.TTS_STATUS;
			break;
		case "order_40":
			order=OrderTye.FROCK_MDVR_CONNECT;
			break;
		case "order_41":
			order=OrderTye.AUDIO_VERIFICATION;
			break;
		case "order_42":
			order=OrderTye.CHANNEL_TEST;
			break;
		case "order_clear":
			order=OrderTye.CLEAR_DATA;
			break;
		case "order_card":
			order=OrderTye.CARD_TEST;
			break;
		case "order_termin":
			order=OrderTye.TERMINAL_NO;
			break;
		case "order_bluetooth":
			order=OrderTye.BLUE_TOOTH;
			break;
		case "order_producerid_old":
			order=OrderTye.PRODUCER_ID_WRITE_OLD;
			break;
		case "order_terminalno_old":
			order=OrderTye.TERMINAL_NO_WRITE_OLD;
			break;
		case "order_producerid_new" :
			order=OrderTye.PRODUCER_ID_WRITE_NEW;
			break;
		case "order_terminalid_new" :
			order=OrderTye.TERMINAL_ID_WRITE_NEW;
			break;
		case "order_terminalphone_new":
			order=OrderTye.TERMINAL_PHONE_WRITE_NEW;
			break;
		case "order_terminalno_new":
			order=OrderTye.TERMINAL_NO_WRITE_NEW;
			break;
		default:
			break;
		}
    	return order;
    }
   public static String  getGpsModelType(int type) {
	   if(type==0) {
		   return "GPS";
	   }else if(type==1) {
		   return "BEIDOU";
	   }else if(type==2) {
		   return "GLONASS";
	   }else if(type==3) {
		   return "Galileo";
	   }else if(type==4) {
		   return "Hybrid";
	   }else if(type==5) {
		   return "GPS+BEIDOU";
	   }else if(type==6) {
		   return "GPS+GLONASS";
	   }else {
		return null;
	}
   }
    public static final class OrderTye{
    	/**时间校验*/
    	public static final byte TIME_CHECK=0x01;
    	/**版本信息*/
    	public static final byte VERSION_GET=0x02;
    	/**MAC地址获取*/
    	public static final byte MAC_GET=0x03;
    	/**MAC地址写入*/
    	public static final byte MAC_WRITE=0x04;
    	/**存储器信息获取*/
    	public static final byte MEMORY_GET=0x05;
    	/**3G模块1信息获取*/
    	public static final byte MODEL_3G1_GET=0x06;
    	/**WIFI信息获取*/
    	public static final byte WIFI_GET=0x07;
    	/**GPS信息获取*/
    	public static final byte GPS_GET=0x08;
    	/**参数导出*/
    	public static final byte PARAMS_EXPORT=0x09;
    	/**参数导入*/
    	public static final byte PARAMS_IMPORT=0x0A;
    	/**恢复出厂*/
    	public static final byte DSM_RESET=0x0B;
    	/**机内温度获取*/
    	public static final byte TEMPERATURE_GET=0x0C;
    	/**机型配置*/
    	public static final byte MODEL_SET=0x0D;
    	/**加密芯片号获取*/
    	public static final byte MICROCHIP_NO_GET=0x0E;
    	/**检测区域版本（战略低端机）*/
    	public static final byte AREA_VERSION_CHECK=0x0F;
    	/**检测区域版本（战略低端机）*/
    	public static final byte AREA_MESSAGE_IMPORT=0x10;
    	/**二维码信息获取*/
    	public static final byte CODE_MESSAGE_GET=0x11;
    	/**3G模块2信息获取*/
    	public static final byte MODEL_3G2_GET=0x12;
    	/**设置时间（DSM）*/
    	public static final byte TIME_SET=0x13;
    	/**格式化*/
    	public static final byte FORMAT_DATA=0x14;
    	/**ACC状态查询（DSM）*/
    	public static final byte ACC_STATUS_SEARCH=0x15;
    	/**3.22 电压查询(外部电压，电池电压，法拉电容电压)（DSM）*/
    	public static final byte VOLTAGE_SEARCH=0x16;
    	/**重启设备（DSM）*/
    	public static final byte RESTART_MACHINE=0x17;
    	/**声音环出*/
    	public static final byte SOUND_GET=0x18;
    	/**声音播放*/
    	public static final byte SOUND_PLAY=0x19;
    	/**声音播放传感器输入状态获取（DSM）*/
    	public static final byte SENSOR_INPUT_STATUS_GET=0x1A;
    	/**控制传感器输出（DSM）*/
    	public static final byte SENSOR_OUTPUT_CONTROL=0x1B;
    	/**手机号写入*/
    	public static final byte PHONE_WRITE=0x1C;
    	/** 
    	 * 奥瞳算法licence鉴别结果广播
    	 * (输入命令无，鉴别结果广播为0x1D)
    	 * */
    	public static final byte LICENCE_CHECK=0x1D;
    	/** 获取奥瞳算法licence鉴别结果*/
    	public static final byte LICENCE_CHECK_GET=0x1E;
    	/**串口测试（AIBOX）*/
    	public static final byte COM_TEST=0x1F;
    	/**六轴测试（AIBOX）*/
    	public static final byte SIX_AXIS_TEST=0x20;
    	/**脉冲测试测试（AIBOX）*/
    	public static final byte PILSE_TEST=0x21;
    	/**硬盘锁状态获取（AIBOX）*/
    	public static final byte HARD_DISK_LOCK=0x22;
    	/**CAN1 口测试 （AIBOX）*/
    	public static final byte CAN1_TEST=0x23;
    	/**CAN2 口测试 （AIBOX）*/
    	public static final byte CAN2_TEST=0x24;
    	/**产品SN写入*/
    	public static final byte SN_WRITE=0x25;
    	/** 查询设备子机型*/
    	public static final byte CHILD_MODEL_SEARCH=0x26;
    	/** 终端ID*/
    	public static final byte TERMINAL_ID=0x27;
    	
    	/** 制造商ID写入old*/
    	public static final byte PRODUCER_ID_WRITE_OLD=0x28;
    	/** 终端型号写入（注册界面）old */
    	public static final byte TERMINAL_NO_WRITE_OLD=0x29;
    	/** 制造商ID写入 new */
    	public static final byte PRODUCER_ID_WRITE_NEW=0x2A;
    	/** 终端ID写入 new */
    	public static final byte TERMINAL_ID_WRITE_NEW=0x2B;
    	/** 终端手机号写入 new  */
    	public static final byte TERMINAL_PHONE_WRITE_NEW=0x2C;
    	/** 终端型号写入 new */
    	public static final byte TERMINAL_NO_WRITE_NEW=0x2D;
    	/** TTS状态*/
    	public static final byte TTS_STATUS=0x2B;
    	/** 工装与MDVR通信*/
    	public static final byte FROCK_MDVR_CONNECT=0x40;
    	/** 音频校验（pc——工装）*/
    	public static final byte AUDIO_VERIFICATION=0x41;
    	/** 通道测试（pc——工装）*/
    	public static final byte CHANNEL_TEST=0x42;
    	
    	/** 清空数据库  */
    	public static final byte CLEAR_DATA=0x2C;
    	/** 刷卡 */
    	public static final byte CARD_TEST=0x28;
    	/** 终端 */
    	public static final byte TERMINAL_NO=0x29;
    	
    	/** 蓝牙 */
    	public static final byte BLUE_TOOTH=0x20;
    	
    	
    }
    /**
     *     将数据解析出来
     * @param data 去掉一帧中多余字节的数据
     * @param order 指令
     * @return
     * @throws Exception 
     */
    public static String  ParsingData(Integer type,byte order,byte[] data,JSONObject map,JSONObject json) throws Exception {
    	String finalDataString=null;
    	switch (order) {
    	
		case OrderTye.TIME_CHECK:
			finalDataString = dealOrder_01(data,map,json);
			break;
		case OrderTye.VERSION_GET:
			if(type==1) {
				finalDataString=dealOrder_02(data,map,json);
			}else if(type==2){
				finalDataString=dealOrder_02_chuzu(data,map,json);
			}
			
			break;
		case OrderTye.MAC_GET:
			finalDataString=dealOrder_03(data,map,json);
			break;
		case OrderTye.MAC_WRITE:
			finalDataString=dealOrder_04(data);
			break;
		case OrderTye.MEMORY_GET:
//			finalDataString=dealOrder_05(data,map,json);
			finalDataString=dealOrder_05_new(data,map,json);
			break;
		case OrderTye.MODEL_3G1_GET:
			if(type==2) { //2代表出租
				finalDataString=dealOrder_06_chuzu(data,map,json);
			}else {
				finalDataString=dealOrder_06(data,map,json);
			}
			break;
		case OrderTye.WIFI_GET:
			finalDataString=dealOrder_07(data,map,json);
			break;
		case OrderTye.GPS_GET:
			finalDataString=dealOrder_08(data,map,json);
			break;
		case OrderTye.PARAMS_EXPORT:
			finalDataString=dealOrder_09(data);
			break;
		case OrderTye.PARAMS_IMPORT:
			finalDataString=dealOrder_09(data);
			break;
		case OrderTye.DSM_RESET:
			finalDataString=dealOrder_09(data);
			break;
		case OrderTye.TEMPERATURE_GET:
			finalDataString=dealOrder_0C(data,json);
			break;
		case OrderTye.MODEL_SET:
			finalDataString=dealOrder_13(data);
			break;
		case OrderTye.MICROCHIP_NO_GET:
			finalDataString=dealOrder_14(data,json);
			break;
		case OrderTye.AREA_VERSION_CHECK:
			finalDataString=dealOrder_15(data);
			break;
		case OrderTye.MODEL_3G2_GET:
			finalDataString=dealOrder_06(data,map,json);
			break;
		case OrderTye.PHONE_WRITE:
			finalDataString=dealOrder_1C(data,json);
			break;
		case OrderTye.SN_WRITE:
			finalDataString=dealOrder_25(data,json);
			break;
		case OrderTye.TERMINAL_ID:
			finalDataString=dealOrder_27(data,json);
			break;
		case OrderTye.CHILD_MODEL_SEARCH:
			if(type==2) {  //2代表出租车
				finalDataString=dealOrder_clear(data);
			}else {
				finalDataString=dealOrder_26(data,map,json);
			}
			break;
		case OrderTye.TTS_STATUS:
			if(type==2) {
				finalDataString=dealOrder_2B(data);
			}else if(type==1){
				finalDataString=dealOrder_Ascii_Write(data,map);
			}
			
			break;
		case OrderTye.CARD_TEST:
			if(type==2) {
				finalDataString=dealOrder_CARD(data,json);
			}else if(type==1) {
				finalDataString=dealOrder_Ascii_Write(data,map);
			}
			break;
		case OrderTye.TERMINAL_NO:
			if(type==2) {
				finalDataString=dealOrder_terNo(data,json);
			}else if(type==1){
				finalDataString=dealOrder_Ascii_Write(data,map);
			}
			break;
		case OrderTye.BLUE_TOOTH:
			if(type==2) {
				finalDataString=dealOrder_blueTooth(data,map,json);
			}
			break;
		case OrderTye.CLEAR_DATA:
			if(type==2) {
				finalDataString=dealOrder_clear(data);
			}else if(type==1){
				finalDataString=dealOrder_Ascii_Write(data,map);
			}
			break;
		case OrderTye.PRODUCER_ID_WRITE_NEW:
			finalDataString=dealOrder_Ascii_Write(data,map);
		case OrderTye.TERMINAL_NO_WRITE_NEW:
			finalDataString=dealOrder_Ascii_Write(data,map);
		default:
			break;
		}
    	return finalDataString;
    }
    
    /**
     * String转byte[]
     * @param hexString
     * @return
     * @throws Exception 
     */
    public static byte[] hexStringToBytes(String hexString) throws Exception {
    	String regex="^[A-Fa-f0-9]+$";
    	if(!hexString.matches(regex)){
    		throw new Exception("该数据不是16进制数字");
    	}
        if (hexString == null || hexString.equals("")) {   
            return null;   
        }   
        hexString = hexString.toUpperCase();   
        int length = hexString.length() / 2;   
        char[] hexChars = hexString.toCharArray();   
        byte[] d = new byte[length];   
        for (int i = 0; i < length; i++) {   
            int pos = i * 2;   
            d[i] = (byte) (charToByte(hexChars[pos]) << 4 | charToByte(hexChars[pos + 1]));   
        }   
        return d;   
    }   
    private static byte charToByte(char c) {   
        return (byte) "0123456789ABCDEF".indexOf(c);   
    }  
    /**
     * 处理时间数据
     * @param data
     * @return
     * @throws Exception
     */
    public static String  dealOrder_01 (byte[] data,JSONObject map,JSONObject json) throws Exception {
    	String finalData=null;
    	if(data.length!=17) {
    		throw new Exception("数据出错！");
    	}
		if(data[0]==0x01) {
			byte[] timeArea=new byte[] {data[2],data[3],data[4]};
			String timeAreaString = FrameUtil.bytesToHexString(timeArea);
			int timeAreaInt = Integer.parseInt(timeAreaString, 16);//分钟转小时
			timeAreaInt=timeAreaInt/60;
			if(data[1]==0x01) {
				timeAreaInt=-timeAreaInt;
			}
			String timeZone = map.getString("timeArea");
			if(StringUtils.isBlank(timeZone)) {
				throw new Exception("时区校验出错，交互配置未配置时区");
			}else if(!timeZone.equals(timeAreaInt+"")) {
				throw new Exception("时区校验出错，工单获取时区："+timeZone+",配置设备时区："+timeAreaInt);
			};
			byte[] date=new byte[] {data[5],data[6]};
			String dateString = FrameUtil.bytesToHexString(date);
			Integer year = Integer.parseInt(dateString, 16)+2000;
			date=new byte[] {data[7],data[8]};
			dateString = FrameUtil.bytesToHexString(date);
			Integer month = Integer.parseInt(dateString, 16);
			date=new byte[] {data[9],data[10]};
			dateString = FrameUtil.bytesToHexString(date);
			Integer day = Integer.parseInt(dateString, 16);
			date=new byte[] {data[11],data[12]};
			dateString = FrameUtil.bytesToHexString(date);
			Integer hour = Integer.parseInt(dateString, 16);
			date=new byte[] {data[13],data[14]};
			dateString = FrameUtil.bytesToHexString(date);
			Integer minute = Integer.parseInt(dateString, 16);
			date=new byte[] {data[15],data[16]};
			dateString = FrameUtil.bytesToHexString(date);
			
			TimeZone.setDefault(null);
			System.clearProperty("user.timezone");
			LocalDateTime now = LocalDateTime.now();
			
			LocalDateTime of = LocalDateTime.of(year, month, day, hour, minute);
			Duration duration = Duration.between(now, of);
			long minutes = duration.toMinutes();
			if(minutes>3||minutes<-3) {
				throw new Exception("时间校验出错，本地时间："+now.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"))+
						"，配置设备时间："+of.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"))+";相差："+minutes);
			}
			String timeString="===>本地时间："+now.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"))+
					"，配置设备时间："+of.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm"))+";相差："+minutes;
			finalData="===> 设备时区："+timeAreaInt+"，工单配置时区："+timeZone+";"+timeString+";测试成功";
			
			//收集测试数据
			json.put("timeArea", String.valueOf(timeAreaInt));
			json.put("machineDate",of);
			
		}else if(data[0]==0x00){
			throw new Exception("数据获取失败！");
		}else {
			throw new Exception("数据出错！");
		}
		return finalData;
	}
    
    public static String dealOrder_Ascii_Write(byte[] data,JSONObject map) throws Exception {
    	commonSuccessCheck(data);
    	String value = map.getString("value");
    	String finalData="数据："+value+"写入成功！";
		return finalData;
		
	}
    //处理蓝牙命令
    public static String  dealOrder_blueTooth(byte[] data,JSONObject map,JSONObject json) throws Exception {
    	String finalData="";
    	commonSuccessCheck(data);
    	String status = map.getString("status");
    	String cnt=map.getString("bluetoothCnt");
    	String cli=map.getString("bluetoothCli");
    	String clo=map.getString("bluetoothClo");
    	String music=map.getString("bluetoothMusic");
    	
     	if(status.equals("1")) {
    		finalData+="播放状态：不检测";
    	}else if(status.equals("2")) {
    		if(StringUtils.isBlank(cnt)||StringUtils.isBlank(cli)||StringUtils.isBlank(clo)||StringUtils.isBlank(music)) {
        		throw new Exception("未配置蓝牙播放内容");
        	}
    		
    		String devCnt="N";
    		String devCli="N";
    		String devClo="N";
    		String devMusic="N";
    		
    		if(data[1]==0x01) {
    			devCnt="Y";
	    	}
    		if(data[2]==0x01) {
    			devCli="Y";
    		}
    		if(data[3]==0x001) {
    			devClo="Y";
    		}
    		if(data[4]==0x001) {
    			devMusic="Y";
    		}
    		
    		//开始判断
    		if(cnt.equals(devCnt)) {
    			finalData+="是否有手机接入："+getYesOrNo(cnt)+";";
    		}else {
    			String msg="手机接入对比：设备返回："+getYesOrNo(devCnt)+" ,配置数据："+getYesOrNo(cnt)+"，对比不同！";
    			throw new Exception(msg);
    		}
    		
    		if(cli.equals(devCli)) {
    			finalData+="是否有电话呼入："+getYesOrNo(cli)+";";
    		}else {
    			String msg="电话呼入对比：设备返回："+getYesOrNo(devCli)+" ,配置数据："+getYesOrNo(cli)+"，对比不同！";
    			throw new Exception(msg);
    		}
    		
    		if(clo.equals(devClo)) {
    			finalData+="是否有电话呼出："+getYesOrNo(clo)+";";
    		}else {
    			String msg="电话呼出对比：设备返回："+getYesOrNo(devClo)+" ,配置数据："+getYesOrNo(clo)+"，对比不同！";
    			throw new Exception(msg);
    		}
    		
    		if(music.equals(devMusic)) {
    			finalData+="是否正在播放蓝牙歌曲："+getYesOrNo(music)+";";
    		}else {
    			String msg="正在播放蓝牙歌曲对比：设备返回："+getYesOrNo(devMusic)+" ,配置数据："+getYesOrNo(music)+"，对比不同！";
    			throw new Exception(msg);
    		}
    		
//    		if(data[1]==0x00) {
//	    		finalData+="CNT(是否有手机接入):否;";
//	    	}else if(data[1]==0x01){
//	    		finalData+="CNT(是否有手机接入):是;";
//	    	}
//	    	if(data[2]==0x00) {
//	    		finalData+="CLI(是否有电话呼入):否;";
//	    	}else if(data[2]==0x01){
//	    		finalData+="CLI(是否有电话呼入):是;";
//	    	}
//	    	if(data[3]==0x00) {
//	    		finalData+="CLO(是否有电话呼出):否;";
//	    	}else if(data[3]==0x01){
//	    		finalData+="CLO(是否有电话呼出):是;";
//	    	}
//	    	if(data[4]==0x00) {
//	    		finalData+="MUSIC(是否正在播放蓝牙歌曲):否;";
//	    	}else if(data[4]==0x01){
//	    		finalData+="MUSIC(是否正在播放蓝牙歌曲):是;";
//	    	}
    	}
    	
    	String version = map.getString("version");
    	if(StringUtils.isNotBlank(version)&&data.length>5) {
    		byte[] addData= new byte[data.length-5];
    		for (int i = 5; i < data.length; i++) {
				addData[i-5]=data[i];
			}
    		String hexString = FrameUtil.AsciiToString(addData);
    		if(StringUtils.isNotBlank(hexString)&&hexString.contains(version)) {
    			finalData+="版本号:"+hexString;
    		}else {
    			String msg="设备版本："+hexString+",配置版本："+version+",测试失败";
    			throw new Exception(msg);
    		}
    	}
    	return finalData+";测试成功";
	}
    
    public static String dealOrder_CARD(byte[] data,JSONObject json) throws Exception {
    	String finalData="";
    	commonSuccessCheck(data);
    	if(data[1]==0x01) {
    		finalData="===>刷卡类型：自制模块";
    	}else if(data[1]==0x02) {
    		finalData="===>刷卡类型：TSM模块";
    	}else if(data[1]==0x03) {
    		finalData="===>刷卡类型：锐明TSM模块";
    	}
    	json.put("cardModel",FrameUtil.bytesToHexString(new byte[] {data[1]}));
    	return finalData+";测试成功";
    }
    
    public static String dealOrder_terNo(byte[] data,JSONObject json) throws Exception {
    	String finalData="";
    	commonSuccessCheck(data);
    	if(data.length>2) {
    		byte[] newdata=new byte[data.length-1];
    		for (int i = 1; i < data.length; i++) {
    			newdata[i-1]=data[i];
			}
    		finalData=FrameUtil.AsciiToString(newdata);
    	}
    	json.put("terminalNo", finalData);
    	return "终端号："+finalData+";测试成功";
    }
    
    public static String dealOrder_clearData(byte[] data) throws Exception {
    	commonSuccessCheck(data);
    	return "成功";
    }
    
    public static String dealOrder_2B(byte[] data) throws Exception {
    	commonSuccessCheck(data);
    	return "成功";
	}
    
    public static String dealOrder_clear(byte[] data) throws Exception {
    	commonSuccessCheck(data);
    	return "清除成功";
    }
    
    public static String dealOrder_02_chuzu(byte[] data,JSONObject map,JSONObject json) throws Exception {
    	String finalData=null;
    	commonSuccessCheck(data);
    	byte[] version=new byte[data.length-1];
    	for(int i=0;i<data.length-1;i++) {
    		version[i]=data[i+1];
    	}
    	String asciiString = FrameUtil.AsciiToString(version);
    	String[] split = asciiString.split(",");  //设备读取的版本信息：出租车数据顺序 1、软件版本，2、IPC版本，3、DH,4、单片机
    	String[] split2 = map.getString("value").split("#");  //配置的版本信息下标： 1、软件版本，2、单片机版本，3、IPC版本，4、卡号
    	String dataString="";
    	String softVerson = map.getString("softVersion");
    	String scmVersion = map.getString("scmVersion");
    	String ipcVersion = map.getString("ipcVersion");
    	String tmsCard = map.getString("tmsCard");
    	for (int i = 0; i < split2.length; i++) {
    		int parseInt = Integer.parseInt(split2[i]);
    		if(parseInt==1) {
    			String msoftVerson="";
    			if(split.length>=1) {
    				msoftVerson=split[0];
    			}
    			if(StringUtils.isNotBlank(softVerson)&&StringUtils.isNotBlank(msoftVerson)&&msoftVerson.equals(softVerson)) {
    				dataString+="===> 本机软件版本号："+msoftVerson+",工单获取软件版本号："+softVerson+",对比结果：相同;";
    				json.put("softVersion", msoftVerson);
    			}else {
    				if(StringUtils.isBlank(msoftVerson)) {
    					dataString="===> （出租）本机软件版本号数据为空，测试失败;";
    					throw new Exception(dataString);
    				}
    				if(StringUtils.isBlank(softVerson)) {
    					dataString="===> （出租）工单获取软件版本号数据为空，测试失败;";
    					throw new Exception(dataString);
    				}
    				dataString+="===> （出租）本机软件版本号："+msoftVerson+",工单获取软件版本号："+softVerson+",对比结果：不同;";
    				throw new Exception(dataString);
    			}
    			
    		}else if(parseInt==2){
    			String mscmVersion="";
    			if(split.length>=4) {
    				mscmVersion=split[3];
    			}
    			if(StringUtils.isNotBlank(scmVersion)&&StringUtils.isNotBlank(mscmVersion)&&mscmVersion.equals(scmVersion)) {
    				dataString+="===> 本机单片机版本号："+mscmVersion+",工单获取单片机版本号："+scmVersion+",对比结果：相同;";
    				json.put("scmVersion", mscmVersion);
    			}else {
    				if(StringUtils.isBlank(mscmVersion)) {
    					dataString="===> （出租）本机单片机版本号数据为空，测试失败;";
    					throw new Exception(dataString);
    				}
    				if(StringUtils.isBlank(scmVersion)) {
    					dataString="===> （出租）工单获取单片机版本号数据为空，测试失败;";
    					throw new Exception(dataString);
    				}
    				dataString+="===> （出租）本机单片机版本号："+mscmVersion+",工单获取单片机版本号："+scmVersion+",对比结果：不同;";
    				throw new Exception(dataString);
    			}
    		}else if(parseInt==3){
    			String mipcVersion="";
    			if(split.length>=2) {
    				mipcVersion=split[1];
    			}
    			if(StringUtils.isNotBlank(ipcVersion)&&StringUtils.isNotBlank(mipcVersion)&&mipcVersion.equals(ipcVersion)) {
    				dataString+="===> 本机IPC版本号："+mipcVersion+",工单获取IPC版本号："+ipcVersion+",对比结果：相同;";
    				json.put("ipcVersion", mipcVersion);
    			}else {
    				if(StringUtils.isBlank(mipcVersion)) {
    					dataString="===> （出租）本机IPC版本号数据为空，测试失败;";
    					throw new Exception(dataString);
    				}
    				if(StringUtils.isBlank(ipcVersion)) {
    					dataString="===> （出租）工单获取IPC版本号数据为空，测试失败;";
    					throw new Exception(dataString);
    				}
    				dataString+="===> （出租）本机IPC版本号："+mipcVersion+",工单获取IPC版本号："+ipcVersion+",对比结果：不同;";
    				throw new Exception(dataString);
    			}
    		}else if(parseInt==4){
    			String mtmsCard="";
    			if(split.length>=3) {
    				mtmsCard=split[2];
    			}
    			if(StringUtils.isNotBlank(tmsCard)&&StringUtils.isNotBlank(mtmsCard)&&mtmsCard.equals(tmsCard)) {
    				dataString+="===> 本机卡号："+mtmsCard+",工单获取卡号："+tmsCard+",对比结果：相同;";
    				json.put("cardVersion", mtmsCard);
    			}else {
    				if(StringUtils.isBlank(mtmsCard)) {
    					dataString="===> （出租）本机卡号数据为空，测试失败;";
    					throw new Exception(dataString);
    				}
    				if(StringUtils.isBlank(tmsCard)) {
    					dataString="===> （出租）工单获取卡号数据为空，测试失败;";
    					throw new Exception(dataString);
    				}
    				dataString+="===> （出租）本机卡号："+mtmsCard+",工单获取卡号："+tmsCard+",对比结果：不同;";
    				throw new Exception(dataString);
    			}
    		}
    		
		}
    	finalData =dataString+"测试成功";
		return finalData;
    }
    
    public static String dealOrder_02_chuzu(OldDataDto oldDataDto,JSONObject map,JSONObject json) throws Exception {
    	String finalData=null;
    	String[] split2 = map.getString("value").split("#");  //配置的版本信息下标： 1、软件版本，2、单片机版本，3、IPC版本，4、卡号
    	String dataString="";
    	String softVerson = map.getString("softVersion");
    	String scmVersion = map.getString("scmVersion");
    	String ipcVersion = map.getString("ipcVersion");
    	String tmsCard = map.getString("tmsCard");
    	String cp4Ver = map.getString("cp4Ver");
    	String firmwareVer = map.getString("firmwareVer");
    	String avver = map.getString("avVer");
    	String watchver = map.getString("watchVer");
    	for (int i = 0; i < split2.length; i++) {
    		int parseInt = Integer.parseInt(split2[i]);
    		if(parseInt==1) {
    			String msoftVerson = oldDataDto.getSoftwareVer();
    			if(StringUtils.isNotBlank(softVerson)&&StringUtils.isNotBlank(msoftVerson)&&msoftVerson.equals(softVerson)) {
    				dataString+="===> 本机软件版本号："+msoftVerson+",工单获取软件版本号："+softVerson+",对比结果：相同;";
    				json.put("softVersion", msoftVerson);
    			}else {
    				if(StringUtils.isBlank(msoftVerson)) {
    					dataString="===> （出租）本机软件版本号数据为空，测试失败;";
    					throw new Exception(dataString);
    				}
    				if(StringUtils.isBlank(softVerson)) {
    					dataString="===> （出租）工单获取软件版本号数据为空，测试失败;";
    					throw new Exception(dataString);
    				}
    				dataString+="===> （出租）本机软件版本号："+msoftVerson+",工单获取软件版本号："+softVerson+",对比结果：不同;";
    				throw new Exception(dataString);
    			}
    			
    		}else if(parseInt==2){
    			String mscmVersion = oldDataDto.getMcu(); 
    			if(StringUtils.isNotBlank(scmVersion)&&StringUtils.isNotBlank(mscmVersion)&&mscmVersion.equals(scmVersion)) {
    				dataString+="===> 本机单片机版本号："+mscmVersion+",工单获取单片机版本号："+scmVersion+",对比结果：相同;";
    				json.put("scmVersion", mscmVersion);
    			}else {
    				if(StringUtils.isBlank(mscmVersion)) {
    					dataString="===> （出租）本机单片机版本号数据为空，测试失败;";
    					throw new Exception(dataString);
    				}
    				if(StringUtils.isBlank(scmVersion)) {
    					dataString="===> （出租）工单获取单片机版本号数据为空，测试失败;";
    					throw new Exception(dataString);
    				}
    				dataString+="===> （出租）本机单片机版本号："+mscmVersion+",工单获取单片机版本号："+scmVersion+",对比结果：不同;";
    				throw new Exception(dataString);
    			}
    		}else if(parseInt==3){
    			String mipcVersion = oldDataDto.getCp4Ver();
    			if(StringUtils.isNotBlank(ipcVersion)&&StringUtils.isNotBlank(mipcVersion)&&mipcVersion.equals(ipcVersion)) {
    				dataString+="===> 本机IPC版本号："+mipcVersion+",工单获取IPC版本号："+ipcVersion+",对比结果：相同;";
    				json.put("ipcVersion", mipcVersion);
    			}else {
    				if(StringUtils.isBlank(mipcVersion)) {
    					dataString="===> （出租）本机IPC版本号数据为空，测试失败;";
    					throw new Exception(dataString);
    				}
    				if(StringUtils.isBlank(ipcVersion)) {
    					dataString="===> （出租）工单获取IPC版本号数据为空，测试失败;";
    					throw new Exception(dataString);
    				}
    				dataString+="===> （出租）本机IPC版本号："+mipcVersion+",工单获取IPC版本号："+ipcVersion+",对比结果：不同;";
    				throw new Exception(dataString);
    			}
    		}else if(parseInt==4){  //暂无
    			String mtmsCard="";
    			if(StringUtils.isNotBlank(tmsCard)&&StringUtils.isNotBlank(mtmsCard)&&mtmsCard.equals(tmsCard)) {
    				dataString+="===> 本机卡号："+mtmsCard+",工单获取卡号："+tmsCard+",对比结果：相同;";
    				json.put("cardVersion", mtmsCard);
    			}else {
    				if(StringUtils.isBlank(mtmsCard)) {
    					dataString="===> （出租）本机卡号数据为空，测试失败;";
    					throw new Exception(dataString);
    				}
    				if(StringUtils.isBlank(tmsCard)) {
    					dataString="===> （出租）工单获取卡号数据为空，测试失败;";
    					throw new Exception(dataString);
    				}
    				dataString+="===> （出租）本机卡号："+mtmsCard+",工单获取卡号："+tmsCard+",对比结果：不同;";
    				throw new Exception(dataString);
    			}
    		} else if(parseInt==5) {
    			String cp4Ver1 = oldDataDto.getCp4Ver();
    			if(StringUtils.isNotBlank(cp4Ver)&& cp4Ver.equals(cp4Ver1)) {
    				dataString+="===> 本机CP3/4版本号："+cp4Ver1+",工单获取CP3/4版本号："+cp4Ver+",对比结果：相同;";
    				json.put("cardVersion", cp4Ver1);
    			}else {
    				dataString+="===> （出租）本机CP3/4版本号："+cp4Ver1+",工单获取CP3/4版本号："+cp4Ver+",对比结果：不同;";
    				throw new Exception(dataString);
    			}
    		} else if (parseInt==6) {
    			String firmwareVer1 = oldDataDto.getFirmwareVer();
    			if(StringUtils.isNotBlank(firmwareVer)&& firmwareVer.equals(firmwareVer1)) {
    				dataString+="===> 本机固件版本："+firmwareVer1+",工单获取固件版本："+firmwareVer+",对比结果：相同;";
    				json.put("cardVersion", firmwareVer1);
    			}else {
    				dataString+="===> （出租）本机固件版本："+firmwareVer1+",工单获取固件版本："+firmwareVer+",对比结果：不同;";
    				throw new Exception(dataString);
    			}
    		} else if (parseInt==7) {
    			String watchver1 = oldDataDto.getWatchver();
    			if(StringUtils.isNotBlank(watchver)&& watchver.equals(watchver1)) {
    				dataString+="===> 本机WATCH版本："+watchver1+",工单获取WATCH版本："+watchver+",对比结果：相同;";
    				json.put("cardVersion", watchver1);
    			}else {
    				dataString+="===> （出租）本机WATCH版本："+watchver1+",工单获取WATCH版本："+watchver+",对比结果：不同;";
    				throw new Exception(dataString);
    			}
    		} else if (parseInt==8) {
    			String avver1 = oldDataDto.getAvver();
    			if(StringUtils.isNotBlank(avver)&& avver.equals(avver1)) {
    				dataString+="===> 本机声光报警器版本："+avver1+",工单获取声光报警器版本："+avver+",对比结果：相同;";
    				json.put("cardVersion", avver1);
    			}else {
    				dataString+="===> （出租）本机声光报警器版本："+avver1+",工单获取声光报警器版本："+avver+",对比结果：不同;";
    				throw new Exception(dataString);
    			}
    		}
		}
    	finalData =dataString+"测试成功";
		return finalData;
    }
    
    
    public static String dealOrder_02_chuzu_2(OldDataDto oldDataDto,JSONObject map,JSONObject json) throws Exception {
    	String finalData=null;
    	String[] split2 = map.getString("value").split("#");  //配置的版本信息下标： 1、软件版本，2、单片机版本，3、IPC版本，4、卡号
    	String dataString="";
    	String softVerson = map.getString("softVersion");
    	String scmVersion = map.getString("scmVersion");
    	String ipcVersion = map.getString("ipcVersion");
    	String tmsCard = map.getString("tmsCard");
    	String cp4Ver = map.getString("cp4Ver");
    	String firmwareVer = map.getString("firmwareVer");
    	String avver = map.getString("avVer");
    	String watchver = map.getString("watchVer");
    	for (int i = 0; i < split2.length; i++) {
    		int parseInt = Integer.parseInt(split2[i]);
    		if(parseInt==1) {
    			if(StringUtils.isBlank(softVerson)) {
					continue;
				}
    			String msoftVerson = oldDataDto.getSoftwareVer();
    			if(StringUtils.isNotBlank(softVerson)&&StringUtils.isNotBlank(msoftVerson)&&msoftVerson.equals(softVerson)) {
    				dataString+="===> 本机软件版本号："+msoftVerson+",工单获取软件版本号："+softVerson+",对比结果：相同;";
    				json.put("softVersion", msoftVerson);
    			}else {
    				if(StringUtils.isBlank(msoftVerson)) {
    					dataString="===> （出租）本机软件版本号数据为空，测试失败;";
    					throw new Exception(dataString);
    				}
    				if(StringUtils.isBlank(softVerson)) {
    					dataString="===> （出租）工单获取软件版本号数据为空，测试失败;";
    					throw new Exception(dataString);
    				}
    				dataString+="===> （出租）本机软件版本号："+msoftVerson+",工单获取软件版本号："+softVerson+",对比结果：不同;";
    				throw new Exception(dataString);
    			}
    			
    		}else if(parseInt==2){
    			if(StringUtils.isBlank(scmVersion)) {
					continue;
				}
    			String mscmVersion = oldDataDto.getMcu(); 
    			if(StringUtils.isNotBlank(scmVersion)&&StringUtils.isNotBlank(mscmVersion)&&mscmVersion.equals(scmVersion)) {
    				dataString+="===> 本机单片机版本号："+mscmVersion+",工单获取单片机版本号："+scmVersion+",对比结果：相同;";
    				json.put("scmVersion", mscmVersion);
    			}else {
    				if(StringUtils.isBlank(mscmVersion)) {
    					dataString="===> （出租）本机单片机版本号数据为空，测试失败;";
    					throw new Exception(dataString);
    				}
    				if(StringUtils.isBlank(scmVersion)) {
    					dataString="===> （出租）工单获取单片机版本号数据为空，测试失败;";
    					throw new Exception(dataString);
    				}
    				dataString+="===> （出租）本机单片机版本号："+mscmVersion+",工单获取单片机版本号："+scmVersion+",对比结果：不同;";
    				throw new Exception(dataString);
    			}
    		}else if(parseInt==3){
    			dataString+="===> （出租）本机IPC版本号暂未获取到;";
    			throw new Exception(dataString);
    		}else if(parseInt==4){  //暂时无
    			dataString+="===> （出租）本机卡号暂未获取到;";
    			throw new Exception(dataString);
    		} else if(parseInt==5) {
    			if(StringUtils.isBlank(cp4Ver)) {
					continue;
				}
    			String cp4Ver1 = oldDataDto.getCp4Ver();
    			if(StringUtils.isNotBlank(cp4Ver)&& cp4Ver.equals(cp4Ver1)) {
    				dataString+="===> 本机CP3/4版本号："+cp4Ver1+",工单获取CP3/4版本号："+cp4Ver+",对比结果：相同;";
    				json.put("cp4Ver", cp4Ver1);
    			}else {
    				dataString+="===> （车载）本机CP3/4版本号："+cp4Ver1+",工单获取CP3/4版本号："+cp4Ver+",对比结果：不同;";
    				throw new Exception(dataString);
    			}
    		} else if (parseInt==6) {
    			if(StringUtils.isBlank(firmwareVer)) {
					continue;
				}
    			String firmwareVer1 = oldDataDto.getFirmwareVer();
    			if(StringUtils.isNotBlank(firmwareVer)&& firmwareVer.equals(firmwareVer1)) {
    				dataString+="===> 本机固件版本："+firmwareVer1+",工单获取固件版本："+firmwareVer+",对比结果：相同;";
    				json.put("firmwareVer", firmwareVer1);
    			}else {
    				dataString+="===> （车载）本机固件版本："+firmwareVer1+",工单获取固件版本："+firmwareVer+",对比结果：不同;";
    				throw new Exception(dataString);
    			}
    		} else if (parseInt==7) {
    			if(StringUtils.isBlank(watchver)) {
					continue;
				}
    			String watchver1 = oldDataDto.getWatchver();
    			if(StringUtils.isNotBlank(watchver)&& watchver.equals(watchver1)) {
    				dataString+="===> 本机WATCH版本："+watchver1+",工单获取WATCH版本："+watchver+",对比结果：相同;";
    				json.put("watchVer", watchver1);
    			}else {
    				dataString+="===> （车载）本机WATCH版本："+watchver1+",工单获取WATCH版本："+watchver+",对比结果：不同;";
    				throw new Exception(dataString);
    			}
    		} else if (parseInt==8) {
    			String avver1 = oldDataDto.getAvver();
    			if(StringUtils.isBlank(avver1)) {
    				dataString+="===> （出租）本机声光报警器版本暂未获取到;";
    				throw new Exception(dataString);
    			}
    			if(StringUtils.isNotBlank(avver)&& avver.equals(avver1)) {
    				dataString+="===> 本机声光报警器版本："+avver1+",工单获取声光报警器版本："+avver+",对比结果：相同;";
    				json.put("cardVersion", avver1);
    			}else {
    				dataString+="===> （出租）本机声光报警器版本："+avver1+",工单获取声光报警器版本："+avver+",对比结果：不同;";
    				throw new Exception(dataString);
    			}
    		}
		}
    	finalData =dataString+"测试成功";
		return finalData;
    }
    
    
    public static String dealOrder_02(byte[] data,JSONObject map,JSONObject json) throws Exception {
    	String finalData=null;
    	commonSuccessCheck(data);
    	byte[] version=new byte[data.length-1];
    	for(int i=0;i<data.length-1;i++) {
    		version[i]=data[i+1];
    	}
    	String asciiString = FrameUtil.AsciiToString(version);
    	String[] split = asciiString.split(",");
    	String[] split2 = map.getString("value").split("#");
    	String dataString="";
    	String softVerson = map.getString("softVersion");
    	String scmVersion = map.getString("scmVersion");
    	String ipcVersion = map.getString("ipcVersion");
    	String tmsCard = map.getString("tmsCard");
    	for (int i = 0; i < split2.length; i++) {
    		int parseInt = Integer.parseInt(split2[i]);
    		if(parseInt==1) {
    			String msoftVerson="";
    			if(split.length>=2) {
    				msoftVerson=split[parseInt-1];
    			}
    			if(StringUtils.isNotBlank(softVerson)&&msoftVerson.equals(softVerson)) {
    				dataString+="===> 本机软件版本号："+msoftVerson+",工单获取软件版本号："+softVerson+",对比结果：相同;";
    				json.put("softVersion", msoftVerson);
    			}else {
    				dataString+="===> （车载）本机软件版本号："+msoftVerson+",工单获取软件版本号："+softVerson+",对比结果：不同;";
    				throw new Exception(dataString);
    			}
    			
    		}else if(parseInt==2){
    			String mscmVersion="";
    			if(split.length>=2) {
    				mscmVersion=split[parseInt-1];
    			}
    			if(StringUtils.isNotBlank(scmVersion)&&mscmVersion.equals(scmVersion)) {
    				dataString+="===> 本机单片机版本号："+mscmVersion+",工单获取单片机版本号："+scmVersion+",对比结果：相同;";
    				json.put("scmVersion", mscmVersion);
    			}else {
    				dataString+="===> （车载）本机单片机版本号："+mscmVersion+",工单获取单片机版本号："+scmVersion+",对比结果：不同;";
    				throw new Exception(dataString);
    			}
    		}else if(parseInt==3){
    			String mipcVersion="";
    			if(split.length>=3) {
    				mipcVersion=split[parseInt-1];
    			}
    			if(StringUtils.isNotBlank(ipcVersion)&&mipcVersion.equals(ipcVersion)) {
    				dataString+="===> 本机IPC版本号："+mipcVersion+",工单获取IPC版本号："+ipcVersion+",对比结果：相同;";
    				json.put("ipcVersion", mipcVersion);
    			}else {
    				dataString+="===> （车载）本机IPC版本号："+mipcVersion+",工单获取IPC版本号："+ipcVersion+",对比结果：不同;";
    				throw new Exception(dataString);
    			}
    		}else if(parseInt==4){
    			String mtmsCard="";
    			if(split.length>=4) {
    				mtmsCard=split[parseInt-1];
    			}
    			if(StringUtils.isNotBlank(tmsCard)&&mtmsCard.equals(tmsCard)) {
    				dataString+="===> 本机卡号："+mtmsCard+",工单获取卡号："+tmsCard+",对比结果：相同;";
    				json.put("cardVersion", mtmsCard);
    			}else {
    				dataString+="===> （车载）本机卡号："+mtmsCard+",工单获取卡号："+tmsCard+",对比结果：不同;";
    				throw new Exception(dataString);
    			}
    		}
    		
		}
    	finalData =dataString+"测试成功";
		return finalData;
	}
    
    public static String dealOrder_02(OldDataDto oldDataDto,JSONObject map,JSONObject json) throws Exception {
    	String finalData = null;
    	String[] split2 = map.getString("value").split("#");
    	String dataString="";
    	String softVerson = map.getString("softVersion");
    	String scmVersion = map.getString("scmVersion");
    	String ipcVersion = map.getString("ipcVersion");
    	String tmsCard = map.getString("tmsCard");
    	String cp4Ver = map.getString("cp4Ver");
    	String firmwareVer = map.getString("firmwareVer");
    	String avver = map.getString("avVer");
    	String watchver = map.getString("watchVer");
    	for (int i = 0; i < split2.length; i++) {
    		int parseInt = Integer.parseInt(split2[i]);
    		if(parseInt==1) {
    			String msoftVerson = oldDataDto.getSoftwareVer();
    			if(StringUtils.isNotBlank(softVerson)&&softVerson.equals(msoftVerson)) {
    				dataString+="===> 本机软件版本号："+msoftVerson+",工单获取软件版本号："+softVerson+",对比结果：相同;";
    				json.put("softVersion", msoftVerson);
    			}else {
    				dataString+="===> （车载）本机软件版本号："+msoftVerson+",工单获取软件版本号："+softVerson+",对比结果：不同;";
    				throw new Exception(dataString);
    			}
    		}else if(parseInt==2){
    			String mscmVersion = oldDataDto.getMcu();
    			if(StringUtils.isNotBlank(scmVersion)&&scmVersion.equals(mscmVersion)) {
    				dataString+="===> 本机单片机版本号："+mscmVersion+",工单获取单片机版本号："+scmVersion+",对比结果：相同;";
    				json.put("scmVersion", mscmVersion);
    			}else {
    				dataString+="===> （车载）本机单片机版本号："+mscmVersion+",工单获取单片机版本号："+scmVersion+",对比结果：不同;";
    				throw new Exception(dataString);
    			}
    		}else if(parseInt==3){
    			dataString+="===> （车载）本机IPC版本号暂未获取到;";
    			throw new Exception(dataString);
    		}else if(parseInt==4){  //暂时无
    			dataString+="===> （车载）本机卡号暂未获取到;";
    			throw new Exception(dataString);
    		} else if(parseInt==5) {
    			String cp4Ver1 = oldDataDto.getCp4Ver();
    			if(StringUtils.isNotBlank(cp4Ver)&& cp4Ver.equals(cp4Ver1)) {
    				dataString+="===> 本机CP3/4版本号："+cp4Ver1+",工单获取CP3/4版本号："+cp4Ver+",对比结果：相同;";
    				json.put("cp4Ver", cp4Ver1);
    			}else {
    				dataString+="===> （车载）本机CP3/4版本号："+cp4Ver1+",工单获取CP3/4版本号："+cp4Ver+",对比结果：不同;";
    				throw new Exception(dataString);
    			}
    		} else if (parseInt==6) {
    			String firmwareVer1 = oldDataDto.getFirmwareVer();
    			if(StringUtils.isNotBlank(firmwareVer)&& firmwareVer.equals(firmwareVer1)) {
    				dataString+="===> 本机固件版本："+firmwareVer1+",工单获取固件版本："+firmwareVer+",对比结果：相同;";
    				json.put("firmwareVer", firmwareVer1);
    			}else {
    				dataString+="===> （车载）本机固件版本："+firmwareVer1+",工单获取固件版本："+firmwareVer+",对比结果：不同;";
    				throw new Exception(dataString);
    			}
    		} else if (parseInt==7) {
    			String watchver1 = oldDataDto.getWatchver();
    			if(StringUtils.isNotBlank(watchver)&& watchver.equals(watchver1)) {
    				dataString+="===> 本机WATCH版本："+watchver1+",工单获取WATCH版本："+watchver+",对比结果：相同;";
    				json.put("watchVer", watchver1);
    			}else {
    				dataString+="===> （车载）本机WATCH版本："+watchver1+",工单获取WATCH版本："+watchver+",对比结果：不同;";
    				throw new Exception(dataString);
    			}
    		} else if (parseInt==8) {
    			String avver1 = oldDataDto.getAvver();
    			if(StringUtils.isNotBlank(avver)&& avver.equals(avver1)) {
    				dataString+="===> 本机声光报警器版本："+avver1+",工单获取声光报警器版本："+avver+",对比结果：相同;";
    				json.put("avVer", avver1);
    			}else {
    				dataString+="===> （车载）本机声光报警器版本："+avver1+",工单获取声光报警器版本："+avver+",对比结果：不同;";
    				throw new Exception(dataString);
    			}
    		}
		}
    	finalData =dataString+"测试成功";
		return finalData;
    }
    
    //Order_02 是否检查avVer(声光版本)
    public static boolean isCheckAvVer(JSONObject map) {
    	boolean flag = false;
    	String[] split2 = map.getString("value").split("#");
    	for (int i = 0; i < split2.length; i++) {
    		int parseInt = Integer.parseInt(split2[i]);
    		if(parseInt==8) {
    			flag = true;
    			break;
    		}
    	}
    	return flag;
    }
    
    public static boolean isCheckWatch(JSONObject map) {
    	boolean flag = false;
    	String[] split2 = map.getString("value").split("#");
    	for (int i = 0; i < split2.length; i++) {
    		int parseInt = Integer.parseInt(split2[i]);
    		if(parseInt==7) {
    			flag = true;
    			break;
    		}
    	}
    	return flag;
    }
    
    public static String dealOrder_02_2(OldDataDto oldDataDto,JSONObject map,JSONObject json) throws Exception {
    	String finalData = null;
    	String[] split2 = map.getString("value").split("#");
    	String dataString="";
    	String softVerson = map.getString("softVersion");
    	String scmVersion = map.getString("scmVersion");
    	String ipcVersion = map.getString("ipcVersion");
    	String tmsCard = map.getString("tmsCard");
    	String cp4Ver = map.getString("cp4Ver");
    	String firmwareVer = map.getString("firmwareVer");
    	String avver = map.getString("avVer");
    	String watchver = map.getString("watchVer");
    	for (int i = 0; i < split2.length; i++) {
    		int parseInt = Integer.parseInt(split2[i]);
    		if(parseInt==1) {
    			if(StringUtils.isBlank(softVerson)) {
    				continue;
    			}
    			String msoftVerson = oldDataDto.getSoftwareVer();
    			if(StringUtils.isNotBlank(softVerson)&&softVerson.equals(msoftVerson)) {
    				dataString+="===> 本机软件版本号："+msoftVerson+",工单获取软件版本号："+softVerson+",对比结果：相同;";
    				json.put("softVersion", msoftVerson);
    			}else {
    				dataString+="===> （车载）本机软件版本号："+msoftVerson+",工单获取软件版本号："+softVerson+",对比结果：不同;";
    				throw new Exception(dataString);
    			}
    		}else if(parseInt==2){
    			if(StringUtils.isBlank(scmVersion)) {
    				continue;
    			}
    			String mscmVersion = oldDataDto.getMcu();
    			if(StringUtils.isNotBlank(scmVersion)&&scmVersion.equals(mscmVersion)) {
    				dataString+="===> 本机单片机版本号："+mscmVersion+",工单获取单片机版本号："+scmVersion+",对比结果：相同;";
    				json.put("scmVersion", mscmVersion);
    			}else {
    				dataString+="===> （车载）本机单片机版本号："+mscmVersion+",工单获取单片机版本号："+scmVersion+",对比结果：不同;";
    				throw new Exception(dataString);
    			}
    		}else if(parseInt==3){
    			dataString+="===> （车载）本机IPC版本号暂未获取到;";
    			throw new Exception(dataString);
    		}else if(parseInt==4){  //暂时无
    			dataString+="===> （车载）本机卡号暂未获取到;";
    			throw new Exception(dataString);
    		} else if(parseInt==5) {
    			if(StringUtils.isBlank(cp4Ver)) {
    				continue;
    			}
    			String cp4Ver1 = oldDataDto.getCp4Ver();
    			if(StringUtils.isNotBlank(cp4Ver)&& cp4Ver.equals(cp4Ver1)) {
    				dataString+="===> 本机CP3/4版本号："+cp4Ver1+",工单获取CP3/4版本号："+cp4Ver+",对比结果：相同;";
    				json.put("cp4Ver", cp4Ver1);
    			}else {
    				dataString+="===> （车载）本机CP3/4版本号："+cp4Ver1+",工单获取CP3/4版本号："+cp4Ver+",对比结果：不同;";
    				throw new Exception(dataString);
    			}
    		} else if (parseInt==6) {
    			if(StringUtils.isBlank(firmwareVer)) {
    				continue;
    			}
    			String firmwareVer1 = oldDataDto.getFirmwareVer();
    			if(StringUtils.isNotBlank(firmwareVer)&& firmwareVer.equals(firmwareVer1)) {
    				dataString+="===> 本机固件版本："+firmwareVer1+",工单获取固件版本："+firmwareVer+",对比结果：相同;";
    				json.put("firmwareVer", firmwareVer1);
    			}else {
    				dataString+="===> （车载）本机固件版本："+firmwareVer1+",工单获取固件版本："+firmwareVer+",对比结果：不同;";
    				throw new Exception(dataString);
    			}
    		} else if (parseInt==7) {
    			if(StringUtils.isBlank(watchver)) {
    				continue;
    			}
    			String watchver1 = oldDataDto.getWatchver();
    			if(StringUtils.isNotBlank(watchver)&& watchver.equals(watchver1)) {
    				dataString+="===> 本机WATCH版本："+watchver1+",工单获取WATCH版本："+watchver+",对比结果：相同;";
    				json.put("watchVer", watchver1);
    			}else {
    				dataString+="===> （车载）本机WATCH版本："+watchver1+",工单获取WATCH版本："+watchver+",对比结果：不同;";
    				throw new Exception(dataString);
    			}
    		} else if (parseInt==8) {
    			String avver1 = oldDataDto.getAvver();
    			if(StringUtils.isBlank(avver1)) {
    				dataString+="===> （车载）本机声光报警器版本暂未获取到;";
    				throw new Exception(dataString);
    			}
    			if(StringUtils.isNotBlank(avver)&& avver.equals(avver1)) {
    				dataString+="===> 本机声光报警器版本："+avver1+",工单获取声光报警器版本："+avver+",对比结果：相同;";
    				json.put("avVer", avver1);
    			}else {
    				dataString+="===> （车载）本机声光报警器版本："+avver1+",工单获取声光报警器版本："+avver+",对比结果：不同;";
    				throw new Exception(dataString);
    			}
    		}
		}
    	finalData =dataString+"测试成功";
		return finalData;
    }
    
    public static String dealOrder_03(byte[] data,JSONObject map,JSONObject json) throws Exception {
    	commonSuccessCheck(data);
    	String fillData=null;
    	String mac = map.getString("value").replaceAll(":", "").replaceAll("：", "").replaceAll("-", "");
    	if(data.length!=7) {
    		throw new Exception("数据出错！");
    	}
		byte[] item1=new byte[] {data[1]};
		byte[] item2=new byte[] {data[2]};
		byte[] item3=new byte[] {data[3]};
		byte[] item4=new byte[] {data[4]};
		byte[] item5=new byte[] {data[5]};
		byte[] item6=new byte[] {data[6]};
		String item1String = FrameUtil.bytesToHexString(item1);
		String item2String = FrameUtil.bytesToHexString(item2);
		String item3String = FrameUtil.bytesToHexString(item3);
		String item4String = FrameUtil.bytesToHexString(item4);
		String item5String = FrameUtil.bytesToHexString(item5);
		String item6String = FrameUtil.bytesToHexString(item6);
		String clearMac=item1String+item2String+item3String+item4String+item5String+item6String;
		fillData="===> 设备MAC地址："+item1String+"-"+item2String+"-"+item3String+"-"+item4String+"-"+item5String+"-"+item6String;
		if(clearMac.equals(mac)) {
			fillData+=";测试成功";
			json.put("macAddress",mac);
		}else {
			fillData+=";输入的mac地址："+mac;
			throw new Exception(fillData);
		}
    	return fillData ;
	}
    
    public static String  dealOrder_04(byte[] data) throws Exception {
    	commonSuccessCheck(data);
    	if(data[0]==0x01) {
    		return "写入成功";
    	}else {
    		return "写入失败";
    	}
	}
    
    public static String dealOrder_05_new(byte[] data,JSONObject map,JSONObject json)throws Exception  {

    	commonSuccessCheck(data);
    	String fillData="";
    	
    	byte[] size=new byte[] {data[1]};
    	int sum = Integer.parseInt(FrameUtil.bytesToHexString(size));
    	json.put("memorySum",sum);
    	int index=2;
    	List<MemoryDto> list=new ArrayList<>();
    	for(int i=0;i<sum;i++) {
    		int type = Integer.parseInt(FrameUtil.bytesToHexString(new byte[] {data[index]}),16);
    		long qty = Long.parseLong(FrameUtil.bytesToHexString(
    					new byte[] {data[index+1],data[index+2],data[index+3],data[index+4],data[index+5],data[index+6],data[index+7],data[index+8]}),16);
    		long finQty=0;
    		if(qty>0) {
    			finQty=qty/(1000*1000*1000);
    		}
    		int number = Integer.parseInt(FrameUtil.bytesToHexString(new byte[] {data[index+9]}),16);
    		
    		index+=10;
    		String typeString="";
    		if(type==1) {
    			typeString="外置";
    		}else if(type==0) {
    			typeString="内置";
    		}
    		
    		String numberType="";
    		String limitString="";
    		if(i==0) {
    			 numberType="自带硬盘";
    			if(map.containsKey("memoryCheckOne")) {
    				
    				 String[] split = map.getString("memoryCheckOne").split("#");
    				 double min=Double.parseDouble(split[0]);
    				 double max=Double.parseDouble(split[1]);
    				 if(min<=finQty&&finQty<=max) {
    					 MemoryDto dto = new MemoryDto();
    					 dto.setMemoryNo(number);
    					 dto.setMemoryType(type);
    					 dto.setMemorySum(finQty);
    					 list.add(dto);
    					 limitString="("+min+"~"+max+")";
    				 }else {
    					 fillData+="===> 类型："+typeString+"；容量："+finQty+"；编号："+numberType+"；输入数据："+min+"~"+max+";测试失败！";
    					 throw new Exception(fillData);
    				 }
    			}else {
    				continue;
    			}
    		}else if(i==1) {
    			numberType="内置SD卡（内置镜像）";
    			if(map.containsKey("memoryCheckTwo")) {
    				
	   				 String[] split = map.getString("memoryCheckTwo").split("#");
	   				 double min=Double.parseDouble(split[0]);
    				 double max=Double.parseDouble(split[1]);
	   				 if(min<=finQty&&finQty<=max) {
	   					 MemoryDto dto = new MemoryDto();
	   					 dto.setMemoryNo(number);
	   					 dto.setMemoryType(type);
	   					 dto.setMemorySum(finQty);
	   					 list.add(dto);
	   					limitString="("+min+"~"+max+")";
	   				 }else {
		   				fillData+="===> 类型："+typeString+"；容量："+finQty+"；编号："+numberType+"；输入数据："+min+"~"+max+";测试失败！";
		   				throw new Exception(fillData);
		   			}
	   			}else {
    				continue;
    			}
    		}else if(i==2) {
    			numberType="外置SD卡（外置镜像）";
    			if(map.containsKey("memoryCheckThree")) {
    				
	   				 String[] split = map.getString("memoryCheckThree").split("#");
	   				 double min=Double.parseDouble(split[0]);
    				 double max=Double.parseDouble(split[1]);
	   				 if(min<=finQty&&finQty<=max) {
	   					 MemoryDto dto = new MemoryDto();
	   					 dto.setMemoryNo(number);
	   					 dto.setMemoryType(type);
	   					 dto.setMemorySum(finQty);
	   					 list.add(dto);
	   					 limitString="("+min+"~"+max+")";
	   				 }else {
		   				fillData+="===> 类型："+typeString+"；容量："+finQty+"；编号："+numberType+"；输入数据："+min+"~"+max+";测试失败！";
		   				throw new Exception(fillData);
		   			}
	   			}else {
    				continue;
    			}
    		}else if(i==3) {
    			numberType="U口";
    			if(map.containsKey("memoryCheckFour")) {
	   				 String[] split = map.getString("memoryCheckFour").split("#");
	   				 double min=Double.parseDouble(split[0]);
    				 double max=Double.parseDouble(split[1]);
	   				 if(min<=finQty&&finQty<=max) {
	   					 MemoryDto dto = new MemoryDto();
	   					 dto.setMemoryNo(number);
	   					 dto.setMemoryType(type);
	   					 dto.setMemorySum(finQty);
	   					 list.add(dto);
	   					 limitString="("+min+"~"+max+")";
	   				 }else {
		   				fillData+="===> 类型："+typeString+"；容量："+finQty+"；编号："+numberType+"；输入数据："+min+"~"+max+";测试失败！";
		   				throw new Exception(fillData);
		   			}
	   			}else {
    				continue;
    			}
    		}else if(i==4) {
    			numberType="固定SD卡";
    			if(map.containsKey("memoryCheckFive")) {
	   				 String[] split = map.getString("memoryCheckFive").split("#");
	   				 double min=Double.parseDouble(split[0]);
    				 double max=Double.parseDouble(split[1]);
	   				 if(min<=finQty&&finQty<=max) {
	   					 MemoryDto dto = new MemoryDto();
	   					 dto.setMemoryNo(number);
	   					 dto.setMemoryType(type);
	   					 dto.setMemorySum(finQty);
	   					 list.add(dto);
	   					 limitString="("+min+"~"+max+")";
	   				 }else {
		   				fillData+="===> 类型："+typeString+"；容量："+finQty+"；编号："+numberType+"；输入数据："+min+"~"+max+";测试失败！";
		   				throw new Exception(fillData);
		   			}
	   			}else {
    				continue;
    			}
    		}else if(i==5) {
    			numberType="外置硬盘";
    			if(map.containsKey("memoryCheckSix")) {
	   				 String[] split = map.getString("memoryCheckSix").split("#");
	   				 double min=Double.parseDouble(split[0]);
    				 double max=Double.parseDouble(split[1]);
	   				 if(min<=finQty&&finQty<=max) {
	   					 MemoryDto dto = new MemoryDto();
	   					 dto.setMemoryNo(number);
	   					 dto.setMemoryType(type);
	   					 dto.setMemorySum(finQty);
	   					 list.add(dto);
	   					 limitString="("+min+"~"+max+")";
	   				 }else {
		   				fillData+="===> 类型："+typeString+"；容量："+finQty+"；编号："+numberType+"；输入数据："+min+"~"+max+";测试失败！";
		   				throw new Exception(fillData);
		   			}
	   			}
    		}else {
				continue;
			}
    		fillData+="===> 类型："+typeString+"；容量："+finQty+"；编号："+numberType+"；设置范围："+limitString+";";
    	}
    	json.put("list", list);
    	return fillData+"测试成功";
	
	}
    
    
    
    public static String dealOrder_05_new(JSONArray data, JSONArray usbData, JSONObject map,JSONObject json)throws Exception  {
    	String fillData="";
    	List<MemoryDto> list=new ArrayList<>();
    	int count = 0;
    	for (int i=0;i<data.size();i++) {
    		Integer internal = data.getJSONObject(i).getInteger("internal");
    		String typeString="";
    		if (internal==0) {
        		typeString="内置";
        	} else {
        		typeString="外置";
        	}
    		long qty = data.getJSONObject(i).getLongValue("left");
    		long total = data.getJSONObject(i).getLongValue("totle");
    		if (total == 0) {
    			continue;
    		}
		    long finQty = 0;
	        if (qty>0) {
	    	    finQty=qty/(1000*1000*1000);
	    	    count++;
	        }
	        Integer number = data.getJSONObject(i).getInteger("id");
	        Integer type = data.getJSONObject(i).getInteger("type");
    		String numberType="";
    		String limitString="";
    		if (type==0&&internal==0) {
   			    numberType="自带硬盘";
   			    if(map.containsKey("memoryCheckOne")) {
   			    	 String[] split = map.getString("memoryCheckOne").split("#");
   			    	 double min=Double.parseDouble(split[0]);
   			    	 double max=Double.parseDouble(split[1]);
   			    	 
   			    	 if(min<=finQty&&finQty<=max) {
   			    		 MemoryDto dto = new MemoryDto();
   			    		 dto.setMemoryNo(number);
   			    		 dto.setMemoryType(internal);
   			    		 dto.setMemorySum(finQty);
   			    		 list.add(dto);
   			    		 limitString="("+min+"~"+max+")";
   			    	 }else {
   			    		 fillData+="===> 类型："+typeString+"；容量："+finQty+"；编号："+numberType+"；输入数据："+min+"~"+max+";测试失败！";
   			    		 throw new Exception(fillData);
   			    	 }
   			    }else {
   			    	continue;
   			    }
   		    } else if(type==0&&internal!=0) {
   		     	numberType="外置硬盘";
		     	if(map.containsKey("memoryCheckSix")) {
   		     		 String[] split = map.getString("memoryCheckSix").split("#");
   		     		 double min=Double.parseDouble(split[0]);
		     		 double max=Double.parseDouble(split[1]);
   		     		 if(min<=finQty&&finQty<=max) {
   		     			 MemoryDto dto = new MemoryDto();
   		     			 dto.setMemoryNo(number);
   		     			 dto.setMemoryType(internal);
   		     			 dto.setMemorySum(finQty);
   		     			 list.add(dto);
   		     			 limitString="("+min+"~"+max+")";
   		     		 }else {
	   	     			fillData+="===> 类型："+typeString+"；容量："+finQty+"；编号："+numberType+"；输入数据："+min+"~"+max+";测试失败！";
	   	     			throw new Exception(fillData);
	   	     		}
   		     	}else {
   		     		continue;
   		     	}
		    } else if(type==1&&internal==0) {
		     	numberType="内置SD卡（内置镜像）";
		     	if(map.containsKey("memoryCheckTwo")) {
   		     		 String[] split = map.getString("memoryCheckTwo").split("#");
   		     		 double min=Double.parseDouble(split[0]);
		     		 double max=Double.parseDouble(split[1]);
   		     		 if(min<=finQty&&finQty<=max) {
   		     			 MemoryDto dto = new MemoryDto();
   		     			 dto.setMemoryNo(number);
   		     			 dto.setMemoryType(internal);
   		     			 dto.setMemorySum(finQty);
   		     			 list.add(dto);
   		     			limitString="("+min+"~"+max+")";
   		     		 }else {
	   	     			fillData+="===> 类型："+typeString+"；容量："+finQty+"；编号："+numberType+"；输入数据："+min+"~"+max+";测试失败！";
	   	     			throw new Exception(fillData);
	   	     		}
   		     	}else {
		     		continue;
		     	}
		    } else if(type==1&&internal!=0) {
		     	numberType="外置SD卡（外置镜像）";
		     	if(map.containsKey("memoryCheckThree")) {
   		     		 String[] split = map.getString("memoryCheckThree").split("#");
   		     		 double min=Double.parseDouble(split[0]);
		     		 double max=Double.parseDouble(split[1]);
   		     		 if(min<=finQty&&finQty<=max) {
   		     			 MemoryDto dto = new MemoryDto();
   		     			 dto.setMemoryNo(number);
   		     			 dto.setMemoryType(internal);
   		     			 dto.setMemorySum(finQty);
   		     			 list.add(dto);
   		     			 limitString="("+min+"~"+max+")";
   		     		 }else {
	   	     			fillData+="===> 类型："+typeString+"；容量："+finQty+"；编号："+numberType+"；输入数据："+min+"~"+max+";测试失败！";
	   	     			throw new Exception(fillData);
	   	     		}
   		     	} else {
		     		continue;
		     	}
		    } else if (type==2){
		    	numberType="U口";
		    	if(map.containsKey("memoryCheckFive")) {
	  				 String[] split = map.getString("memoryCheckFive").split("#");
	  				 double min=Double.parseDouble(split[0]);
					 double max=Double.parseDouble(split[1]);
	  				 if(min<=finQty&&finQty<=max) {
	  					 MemoryDto dto = new MemoryDto();
	  					 dto.setMemoryNo(number);
	  					 dto.setMemoryType(1);
	  					 dto.setMemorySum(finQty);
	  					 list.add(dto);
	  					 limitString="("+min+"~"+max+")";
	  				 }else {
		   				fillData+="===> 类型："+typeString+"；容量："+finQty+"；编号："+numberType+"；输入数据："+min+"~"+max+";测试失败！";
		   				throw new Exception(fillData);
		   			}
	   			} else {
					continue;
				}
		    } else {
		     	continue;
		    }
    		fillData+="===> 类型："+typeString+"；容量："+finQty+"；编号："+numberType+"；设置范围："+limitString+";";
    	}
    	int moCount = 0;
    	for(String key : "memoryCheckOne,memoryCheckTwo,memoryCheckThree,memoryCheckFour,memoryCheckFive,memoryCheckSix".split(",")) {
    		if(map.containsKey(key)) {
        		moCount++;
        	}
    	}
    	if(moCount > count) {
    		fillData+="===> 存储设备测试数量："+moCount+"；存储设备实际数量："+count+"；比对结果：大于;测试失败！";
			throw new Exception(fillData);
    	}
    	
    	json.put("memorySum", count);
    	json.put("list", list);
    	return fillData+"测试成功";		
	
	}
    
    
    public static String dealOrder_05_new2(JSONArray data, JSONArray usbData, JSONObject map,JSONObject json)throws Exception  {
    	String fillData="";
    	List<MemoryDto> list=new ArrayList<>();
    	int count = 0;
    	for (int i=0;i<data.size();i++) {
    		Integer internal = data.getJSONObject(i).getInteger("position");
    		String typeString="";
    		if (internal==0) {
        		typeString="内置";
        	} else {
        		typeString="外置";
        	}
    		long qty = data.getJSONObject(i).getLongValue("freeSize");
    		long total = data.getJSONObject(i).getLongValue("totalSize");
    		if (total == 0) {
    			continue;
    		}
		    long finQty = 0;
	        if (qty>0) {
	    	    finQty=qty/(1000*1000*1000);
	    	    count++;
	        }
	        Integer number = data.getJSONObject(i).getInteger("devId");
	        Integer type = data.getJSONObject(i).getInteger("devType");
    		String numberType="";
    		String limitString="";
    		if (type==2&&internal==0) {
   			    numberType="自带硬盘";
   			    if(map.containsKey("memoryCheckOne")) {
   			    	 String[] split = map.getString("memoryCheckOne").split("#");
   			    	 double min=Double.parseDouble(split[0]);
   			    	 double max=Double.parseDouble(split[1]);
   			    	 
   			    	 if(min<=finQty&&finQty<=max) {
   			    		 MemoryDto dto = new MemoryDto();
   			    		 dto.setMemoryNo(number);
   			    		 dto.setMemoryType(internal);
   			    		 dto.setMemorySum(finQty);
   			    		 list.add(dto);
   			    		 limitString="("+min+"~"+max+")";
   			    	 }else {
   			    		 fillData+="===> 类型："+typeString+"；容量："+finQty+"；编号："+numberType+"；输入数据："+min+"~"+max+";测试失败！";
   			    		 throw new Exception(fillData);
   			    	 }
   			    }else {
   			    	continue;
   			    }
   		    } else if(type==2&&internal!=0) {
   		     	numberType="外置硬盘";
		     	if(map.containsKey("memoryCheckSix")) {
   		     		 String[] split = map.getString("memoryCheckSix").split("#");
   		     		 double min=Double.parseDouble(split[0]);
		     		 double max=Double.parseDouble(split[1]);
   		     		 if(min<=finQty&&finQty<=max) {
   		     			 MemoryDto dto = new MemoryDto();
   		     			 dto.setMemoryNo(number);
   		     			 dto.setMemoryType(internal);
   		     			 dto.setMemorySum(finQty);
   		     			 list.add(dto);
   		     			 limitString="("+min+"~"+max+")";
   		     		 }else {
	   	     			fillData+="===> 类型："+typeString+"；容量："+finQty+"；编号："+numberType+"；输入数据："+min+"~"+max+";测试失败！";
	   	     			throw new Exception(fillData);
	   	     		}
   		     	}else {
   		     		continue;
   		     	}
		    } else if(type==1&&internal==0) {
		     	numberType="内置SD卡（内置镜像）";
		     	if(map.containsKey("memoryCheckTwo")) {
   		     		 String[] split = map.getString("memoryCheckTwo").split("#");
   		     		 double min=Double.parseDouble(split[0]);
		     		 double max=Double.parseDouble(split[1]);
   		     		 if(min<=finQty&&finQty<=max) {
   		     			 MemoryDto dto = new MemoryDto();
   		     			 dto.setMemoryNo(number);
   		     			 dto.setMemoryType(internal);
   		     			 dto.setMemorySum(finQty);
   		     			 list.add(dto);
   		     			limitString="("+min+"~"+max+")";
   		     		 }else {
	   	     			fillData+="===> 类型："+typeString+"；容量："+finQty+"；编号："+numberType+"；输入数据："+min+"~"+max+";测试失败！";
	   	     			throw new Exception(fillData);
	   	     		}
   		     	}else {
		     		continue;
		     	}
		    } else if(type==1&&internal!=0) {
		     	numberType="外置SD卡（外置镜像）";
		     	if(map.containsKey("memoryCheckThree")) {
   		     		 String[] split = map.getString("memoryCheckThree").split("#");
   		     		 double min=Double.parseDouble(split[0]);
		     		 double max=Double.parseDouble(split[1]);
   		     		 if(min<=finQty&&finQty<=max) {
   		     			 MemoryDto dto = new MemoryDto();
   		     			 dto.setMemoryNo(number);
   		     			 dto.setMemoryType(internal);
   		     			 dto.setMemorySum(finQty);
   		     			 list.add(dto);
   		     			 limitString="("+min+"~"+max+")";
   		     		 }else {
	   	     			fillData+="===> 类型："+typeString+"；容量："+finQty+"；编号："+numberType+"；输入数据："+min+"~"+max+";测试失败！";
	   	     			throw new Exception(fillData);
	   	     		}
   		     	} else {
		     		continue;
		     	}
		    } else if (type==0){
		    	numberType="U口";
		    	if(map.containsKey("memoryCheckFive")) {
	  				 String[] split = map.getString("memoryCheckFive").split("#");
	  				 double min=Double.parseDouble(split[0]);
					 double max=Double.parseDouble(split[1]);
	  				 if(min<=finQty&&finQty<=max) {
	  					 MemoryDto dto = new MemoryDto();
	  					 dto.setMemoryNo(number);
	  					 dto.setMemoryType(1);
	  					 dto.setMemorySum(finQty);
	  					 list.add(dto);
	  					 limitString="("+min+"~"+max+")";
	  				 }else {
		   				fillData+="===> 类型："+typeString+"；容量："+finQty+"；编号："+numberType+"；输入数据："+min+"~"+max+";测试失败！";
		   				throw new Exception(fillData);
		   			}
	   			} else {
					continue;
				}
		    } else {
		     	continue;
		    }
    		fillData+="===> 类型："+typeString+"；容量："+finQty+"；编号："+numberType+"；设置范围："+limitString+";";
    	}
    	int moCount = 0;
    	for(String key : "memoryCheckOne,memoryCheckTwo,memoryCheckThree,memoryCheckFour,memoryCheckFive,memoryCheckSix".split(",")) {
    		if(map.containsKey(key)) {
        		moCount++;
        	}
    	}
    	if(moCount > count) {
    		fillData+="===> 存储设备测试数量："+moCount+"；存储设备实际数量："+count+"；比对结果：大于;测试失败！";
			throw new Exception(fillData);
    	}
    	
    	json.put("memorySum", count);
    	json.put("list", list);
    	return fillData+"测试成功";		
	
	}
    
    public static String  dealOrder_05(byte[] data,JSONObject map,JSONObject json) throws Exception {
    	commonSuccessCheck(data);
    	String fillData="";
    	boolean type1=false; //编号1成功标志
    	boolean type2=false; //编号2成功标志
    	boolean type3=false; //编号3成功标志
    	boolean type4=false; //编号4成功标志
    	boolean type5=false; //编号5成功标志
    	boolean type6=false; //编号6成功标志
    	
    	byte[] size=new byte[] {data[1]};
    	int sum = Integer.parseInt(FrameUtil.bytesToHexString(size));
    	json.put("memorySum",sum);
    	int index=2;
    	List<MemoryDto> list=new ArrayList<>();
    	for(int i=0;i<sum;i++) {
    		int type = Integer.parseInt(FrameUtil.bytesToHexString(new byte[] {data[index]}),16);
    		long qty = Long.parseLong(FrameUtil.bytesToHexString(
    					new byte[] {data[index+1],data[index+2],data[index+3],data[index+4],data[index+5],data[index+6],data[index+7],data[index+8]}),16);
    		long finQty=0;
    		if(qty>0) {
    			finQty=qty/(1000*1000*1000);
    		}
    		int number = Integer.parseInt(FrameUtil.bytesToHexString(new byte[] {data[index+9]}),16);
    		
    		index+=10;
    		String typeString="";
    		if(type==1) {
    			typeString="外置";
    		}else if(type==0) {
    			typeString="内置";
    		}
    		
    		String numberType="";
    		String limitString="";
    		if(number==1) {
    			 numberType="自带硬盘";
    			if(map.containsKey("memoryCheckOne")) {
    				if(finQty==0&&type1) {  //该内存为最后置0的内存
    					continue;
    				}
    				 String[] split = map.getString("memoryCheckOne").split("#");
    				 double min=Double.parseDouble(split[0]);
    				 double max=Double.parseDouble(split[1]);
    				 if(min<=finQty&&finQty<=max) {
    					 MemoryDto dto = new MemoryDto();
    					 dto.setMemoryNo(number);
    					 dto.setMemoryType(type);
    					 dto.setMemorySum(finQty);
    					 list.add(dto);
    					 limitString="("+min+"~"+max+")";
    					 type1=true;  //编号1测试已经通过
    				 }else {
    					 fillData+="===> 类型："+typeString+"；容量："+finQty+"；编号："+numberType+"；输入数据："+min+"~"+max+";测试失败！";
    					 throw new Exception(fillData);
    				 }
    			}else {
    				continue;
    			}
    		}else if(number==2) {
    			numberType="内置SD卡（内置镜像）";
    			if(map.containsKey("memoryCheckTwo")) {
    				if(finQty==0&&type2) {  //该内存为最后置0的内存
    					continue;
    				}
	   				 String[] split = map.getString("memoryCheckTwo").split("#");
	   				 double min=Double.parseDouble(split[0]);
    				 double max=Double.parseDouble(split[1]);
	   				 if(min<=finQty&&finQty<=max) {
	   					 MemoryDto dto = new MemoryDto();
	   					 dto.setMemoryNo(number);
	   					 dto.setMemoryType(type);
	   					 dto.setMemorySum(finQty);
	   					 list.add(dto);
	   					limitString="("+min+"~"+max+")";
	   					type2=true;
	   				 }else {
		   				fillData+="===> 类型："+typeString+"；容量："+finQty+"；编号："+numberType+"；输入数据："+min+"~"+max+";测试失败！";
		   				throw new Exception(fillData);
		   			}
	   			}else {
    				continue;
    			}
    		}else if(number==3) {
    			numberType="外置SD卡（外置镜像）";
    			if(map.containsKey("memoryCheckThree")) {
    				if(finQty==0&&type3) {  //该内存为最后置0的内存
    					continue;
    				}
	   				 String[] split = map.getString("memoryCheckThree").split("#");
	   				 double min=Double.parseDouble(split[0]);
    				 double max=Double.parseDouble(split[1]);
	   				 if(min<=finQty&&finQty<=max) {
	   					 MemoryDto dto = new MemoryDto();
	   					 dto.setMemoryNo(number);
	   					 dto.setMemoryType(type);
	   					 dto.setMemorySum(finQty);
	   					 list.add(dto);
	   					 limitString="("+min+"~"+max+")";
	   					 type3=true;
	   				 }else {
		   				fillData+="===> 类型："+typeString+"；容量："+finQty+"；编号："+numberType+"；输入数据："+min+"~"+max+";测试失败！";
		   				throw new Exception(fillData);
		   			}
	   			}else {
    				continue;
    			}
    		}else if(number==4) {
    			numberType="U口";
    			if(map.containsKey("memoryCheckFour")) {
    				if(finQty==0&&type4) {  //该内存为最后置0的内存
    					continue;
    				}
	   				 String[] split = map.getString("memoryCheckFour").split("#");
	   				 double min=Double.parseDouble(split[0]);
    				 double max=Double.parseDouble(split[1]);
	   				 if(min<=finQty&&finQty<=max) {
	   					 MemoryDto dto = new MemoryDto();
	   					 dto.setMemoryNo(number);
	   					 dto.setMemoryType(type);
	   					 dto.setMemorySum(finQty);
	   					 list.add(dto);
	   					 limitString="("+min+"~"+max+")";
	   					 type4=true;
	   				 }else {
		   				fillData+="===> 类型："+typeString+"；容量："+finQty+"；编号："+numberType+"；输入数据："+min+"~"+max+";测试失败！";
		   				throw new Exception(fillData);
		   			}
	   			}else {
    				continue;
    			}
    		}else if(number==5) {
    			numberType="固定SD卡";
    			if(map.containsKey("memoryCheckFive")) {
    				if(finQty==0&&type5) {  //该内存为最后置0的内存
    					continue;
    				}
	   				 String[] split = map.getString("memoryCheckFive").split("#");
	   				 double min=Double.parseDouble(split[0]);
    				 double max=Double.parseDouble(split[1]);
	   				 if(min<=finQty&&finQty<=max) {
	   					 MemoryDto dto = new MemoryDto();
	   					 dto.setMemoryNo(number);
	   					 dto.setMemoryType(type);
	   					 dto.setMemorySum(finQty);
	   					 list.add(dto);
	   					 limitString="("+min+"~"+max+")";
	   					 type5=true;
	   				 }else {
		   				fillData+="===> 类型："+typeString+"；容量："+finQty+"；编号："+numberType+"；输入数据："+min+"~"+max+";测试失败！";
		   				throw new Exception(fillData);
		   			}
	   			}else {
    				continue;
    			}
    		}else if(number==6) {
    			numberType="外置硬盘";
    			if(map.containsKey("memoryCheckSix")) {
    				if(finQty==0&&type6) {  //该内存为最后置0的内存
    					continue;
    				}
	   				 String[] split = map.getString("memoryCheckSix").split("#");
	   				 double min=Double.parseDouble(split[0]);
    				 double max=Double.parseDouble(split[1]);
	   				 if(min<=finQty&&finQty<=max) {
	   					 MemoryDto dto = new MemoryDto();
	   					 dto.setMemoryNo(number);
	   					 dto.setMemoryType(type);
	   					 dto.setMemorySum(finQty);
	   					 list.add(dto);
	   					 limitString="("+min+"~"+max+")";
	   					 type6=true;
	   				 }else {
		   				fillData+="===> 类型："+typeString+"；容量："+finQty+"；编号："+numberType+"；输入数据："+min+"~"+max+";测试失败！";
		   				throw new Exception(fillData);
		   			}
	   			}
    		}else {
				continue;
			}
    		fillData+="===> 类型："+typeString+"；容量："+finQty+"；编号："+numberType+"；设置范围："+limitString+";";
    	}
    	json.put("list", list);
    	return fillData+"测试成功";
	}
    
    public static String dealOrder_06_chuzu(byte[] data,JSONObject map,JSONObject json) throws Exception {
    	commonSuccessCheck(data);
    	String fillData="";
    	int modelStatus = Integer.parseInt(FrameUtil.bytesToHexString(new byte[] {data[1]}), 16);
    	int modelType = Integer.parseInt(FrameUtil.bytesToHexString(new byte[] {data[2]}), 16);
    	int dialStatus= Integer.parseInt(FrameUtil.bytesToHexString(new byte[] {data[3]}), 16);
    	int signal = Integer.parseInt(FrameUtil.bytesToHexString(new byte[] {data[4]}), 16);
    	String chatSignalString = map.getString("chatSignal");
    	if(StringUtils.isBlank(chatSignalString)) {
    		chatSignalString="0";
    	}
    	Integer chatSignal =Integer.parseInt(chatSignalString);
    	if(chatSignal!=null&&signal<chatSignal) {
    		throw new Exception("信号强度不正确;设备信号强度："+signal+"，配置信号强度："+chatSignal+"测试失败！");
    	}else {
    		json.put("chatSignal", String.valueOf(signal));
    	}
    	
    	fillData+="===>信号强度："+signal+";";
    	
    	String byteType = map.getString("byteType");

    	byte[] imei=new byte[15];
    	for(int i=0;i<15;i++) {
    		imei[i]=data[i+5];
    	}
    	String imeiString =FrameUtil.AsciiToString(imei);
    	json.put("chatImei", imeiString);
    	
    	fillData+="===>IMEI号："+imeiString+";";
    	
    	byte[] ip=new byte[4];
    	for(int i=0;i<4;i++) {
    		ip[i]=data[i+20];
    	}
    	int ip1 =Integer.parseInt(FrameUtil.bytesToHexString(new byte[] {ip[0]}),16);
    	int ip2 =Integer.parseInt(FrameUtil.bytesToHexString(new byte[] {ip[1]}),16);
    	int ip3 =Integer.parseInt(FrameUtil.bytesToHexString(new byte[] {ip[2]}),16);
    	int ip4 =Integer.parseInt(FrameUtil.bytesToHexString(new byte[] {ip[3]}),16);
    	json.put("chatIp",ip1+"."+ip2+"."+ip3+"."+ip4);
    	
    	String modelStatusString="";
    	if(modelStatus==0) {
    		modelStatusString="模块不正常";
    		throw new Exception(modelStatusString+";测试失败");
    	}else if(modelStatus==1) {
    		modelStatusString="模块正常";
    	}
    	json.put("chatModelStatus", String.valueOf(modelStatus));
    	fillData+="===>模块状态："+modelStatusString+";";
    	
    	Integer chatType = Integer.parseInt(map.getString("chatType"));
    	String modelTypeString=getChatModelType(modelType);
    	String setTypeString=getChatModelType(chatType);
    	
    	if(chatType==8) {
    		chatType=7;
    	}
    	if(modelType==8) {
    		modelType=7;
    	}
    	if(chatType!=null&&chatType!=modelType) {
    		throw new Exception("模块类型不正确;设备模块："+modelTypeString+"，配置模块类型："+setTypeString+";测试失败");
    	}
    	
    	json.put("chatModelType", String.valueOf(modelType));
    	fillData+="===>模块类型："+modelTypeString+";";
    	
    	String callStatus = map.getString("callStatus");
    	if("1".equals(callStatus)&&dialStatus==0) {
    		throw new Exception("通讯模块拨号状态：拨号失败！");
    	}
    	String dialStatusString="";
    	if(dialStatus==0) {
    		dialStatusString="拨号失败";
    	}else if(dialStatus==1) {
    		dialStatusString="拨号成功";
    	}
    	json.put("chatDialingStatus", String.valueOf(dialStatus));
    	fillData+="===>拨号状态："+dialStatusString+";";
    	
    	String chatVersion = map.getString("chatVersion");
    	
    	if("1".equals(byteType)) {
    		if(data.length>24&&StringUtils.isNotBlank(chatVersion)) {
    			int versionLong = Integer.parseInt(FrameUtil.bytesToHexString(new byte[] {data[24]}), 16);
        		int size=data.length-25;
    	    	byte[] version=new byte[versionLong];
    	    	for(int i=0;i<size;i++) {
    	    		version[i]=data[i+25];
    	    	}
    	    	String versionString = FrameUtil.AsciiToString(version);
    	    	
    	    	if(StringUtils.isNotBlank(versionString)&&!versionString.contains(chatVersion)) {
    	    		throw new Exception("获取版本号不正确,设备版本号："+versionString+",配置版本信息："+chatVersion+";测试失败");
    	    	}
    	    	json.put("chatVersion",chatVersion);
    	    	fillData+="===>IP地址："+ip1+"."+ip2+"."+ip3+"."+ip4+";===>模块软件版本号长度："
    	    			+versionLong+";===>模块软件版本号："+versionString;
    		}else if(StringUtils.isBlank(chatVersion)){
    			throw new Exception("未配置通讯模块版本号");
    		}else if(data.length<=24) {
    			throw new Exception("从设备获取的数据长度不足，请确认是否32B");
    		}
    	}else {
    		if(data.length>24&&data[24]!=0x00) {
    			throw new Exception("从设备获取的数据长度多于设定值，请确认是否15B");
    		}
    	}
    	
    	return fillData+";测试成功";
	}
    
    public static String dealOrder_06(byte[] data,JSONObject map,JSONObject json) throws Exception {
    	commonSuccessCheck(data);
    	String fillData="";
    	int modelStatus = Integer.parseInt(FrameUtil.bytesToHexString(new byte[] {data[1]}), 16);
    	int modelType = Integer.parseInt(FrameUtil.bytesToHexString(new byte[] {data[2]}), 16);
    	int dialStatus= Integer.parseInt(FrameUtil.bytesToHexString(new byte[] {data[3]}), 16);
    	int signal = Integer.parseInt(FrameUtil.bytesToHexString(new byte[] {data[4]}), 16);
    	String chatSignalString = map.getString("chatSignal");
    	if(StringUtils.isBlank(chatSignalString)) {
    		chatSignalString="0";
    	}
    	Integer chatSignal =Integer.parseInt(chatSignalString);
    	if(chatSignal!=null&&signal<chatSignal) {
    		throw new Exception("信号强度不正确;设备信号强度："+signal+"，配置信号强度："+chatSignal+"测试失败！");
    	}else {
    		json.put("chatSignal", String.valueOf(signal));
    	}
    	
    	fillData+="===>信号强度："+signal+";";
    	
    	
    	byte[] imei=new byte[32];
    	for(int i=0;i<32;i++) {
    		imei[i]=data[i+5];
    	}
    	String imeiString =FrameUtil.AsciiToString(imei);
    	json.put("chatImei", imeiString);
    	
    	fillData+="===>IMEI号："+imeiString+";";
    	
    	byte[] ip=new byte[4];
    	for(int i=0;i<4;i++) {
    		ip[i]=data[i+37];
    	}
    	int ip1 =Integer.parseInt(FrameUtil.bytesToHexString(new byte[] {ip[0]}),16);
    	int ip2 =Integer.parseInt(FrameUtil.bytesToHexString(new byte[] {ip[1]}),16);
    	int ip3 =Integer.parseInt(FrameUtil.bytesToHexString(new byte[] {ip[2]}),16);
    	int ip4 =Integer.parseInt(FrameUtil.bytesToHexString(new byte[] {ip[3]}),16);
    	json.put("chatIp",ip1+"."+ip2+"."+ip3+"."+ip4);
    	
    	
    	
    	String modelStatusString="";
    	if(modelStatus==0) {
    		modelStatusString="模块不正常";
    		throw new Exception(modelStatusString+";测试失败");
    	}else if(modelStatus==1) {
    		modelStatusString="模块正常";
    	}
    	json.put("chatModelStatus", String.valueOf(modelStatus));
    	fillData+="===>模块状态："+modelStatusString+";";
    	
    	Integer chatType = Integer.parseInt(map.getString("chatType"));
    	String modelTypeString=getChatModelType(modelType);
    	String setTypeString=getChatModelType(chatType);
    	
    	if(chatType==8) {
    		chatType=7;
    	}
    	if(modelType==8) {
    		modelType=7;
    	}
    	if(chatType!=null&&chatType!=modelType) {
    		throw new Exception("模块类型不正确;设备模块："+modelTypeString+"，配置模块类型："+setTypeString+";测试失败");
    	}
    	
    	json.put("chatModelType", String.valueOf(modelType));
    	fillData+="===>模块类型："+modelTypeString+";";
    	
    	String callStatus = map.getString("callStatus");
    	if("1".equals(callStatus)&&dialStatus==0) {
    		throw new Exception("通讯模块拨号状态：拨号失败！");
    	}
    	
    	String dialStatusString="";
    	if(dialStatus==0) {
    		dialStatusString="拨号失败";
    	}else if(dialStatus==1) {
    		dialStatusString="拨号成功";
    	}
    	json.put("chatDialingStatus", String.valueOf(dialStatus));
    	
    	String chatVersion = map.getString("chatVersion");
    	fillData+="===>拨号状态："+dialStatusString+";";
    	
    	String byteType = map.getString("byteType");
    	if("1".equals(byteType)) {
    		if(data.length>41&&StringUtils.isNotBlank(chatVersion)) {
    			int versionLong = Integer.parseInt(FrameUtil.bytesToHexString(new byte[] {data[41]}), 16);
        		int size=data.length-42;
    	    	byte[] version=new byte[versionLong];
    	    	for(int i=0;i<size;i++) {
    	    		version[i]=data[i+42];
    	    	}
    	    	String versionString = FrameUtil.AsciiToString(version);
    	    	
    	    	if(StringUtils.isNotBlank(versionString)&&!versionString.contains(chatVersion)) {
    	    		throw new Exception("获取版本号不正确,设备版本号："+versionString+",配置版本信息："+chatVersion+";测试失败");
    	    	}
    	    	json.put("chatVersion",chatVersion);
    	    	fillData+="===>IP地址："+ip1+"."+ip2+"."+ip3+"."+ip4+";===>模块软件版本号长度："
    	    			+versionLong+";===>模块软件版本号："+versionString;
    		}else if(StringUtils.isBlank(chatVersion)){
    			throw new Exception("未配置通讯模块版本号");
    		}else if(data.length<=41) {
    			throw new Exception("从设备获取的数据长度不足，请确认是否32B");
    		}
    	}else {
    		if(data.length>41&&data[41]!=0x00) {
    			throw new Exception("从设备获取的数据长度多于设定值，请确认是否15B");
    		}
    	}
    	
    	return fillData+";测试成功";
	}
    
    
    
    public static String dealOrder_06_GET(byte[] data,JSONObject json) throws Exception {
    	commonSuccessCheck(data);
    	String fillData="";
    	int modelStatus = Integer.parseInt(FrameUtil.bytesToHexString(new byte[] {data[1]}), 16);
    	int modelType = Integer.parseInt(FrameUtil.bytesToHexString(new byte[] {data[2]}), 16);
    	int dialStatus= Integer.parseInt(FrameUtil.bytesToHexString(new byte[] {data[3]}), 16);
    	int signal = Integer.parseInt(FrameUtil.bytesToHexString(new byte[] {data[4]}), 16);
    	
    	json.put("chatSignal", String.valueOf(signal));
    	
    	fillData+="<div>===>信号强度："+signal+"</div>";
    	
    	int imeiSize=32;
    	byte[] imei=new byte[imeiSize];
    	for(int i=0;i<imeiSize;i++) {
    		imei[i]=data[i+5];
    	}
    	String imeiString =FrameUtil.AsciiToString(imei);
    	json.put("chatImei", imeiString);
    	
    	fillData+="<div>===>IMEI号："+imeiString+"</div>";
    	
    	byte[] ip=new byte[4];
    	for(int i=0;i<4;i++) {
    		ip[i]=data[i+37];
    	}
    	int ip1 =Integer.parseInt(FrameUtil.bytesToHexString(new byte[] {ip[0]}),16);
    	int ip2 =Integer.parseInt(FrameUtil.bytesToHexString(new byte[] {ip[1]}),16);
    	int ip3 =Integer.parseInt(FrameUtil.bytesToHexString(new byte[] {ip[2]}),16);
    	int ip4 =Integer.parseInt(FrameUtil.bytesToHexString(new byte[] {ip[3]}),16);
    	json.put("chatIp",ip1+"."+ip2+"."+ip3+"."+ip4);
    	
    	String modelStatusString="";
    	if(modelStatus==0) {
    		modelStatusString="模块不正常";
    		throw new Exception(modelStatusString+";测试失败");
    	}else if(modelStatus==1) {
    		modelStatusString="模块正常";
    	}
    	json.put("chatModelStatus", String.valueOf(modelStatus));
    	fillData+="<div>===>模块状态："+modelStatusString+"</div>";
    	
    	String modelTypeString=getChatModelType(modelType);
    	json.put("chatModelType", String.valueOf(modelType));
    	fillData+="<div>===>模块类型："+modelTypeString+"</div>";
    	
    	String dialStatusString="";
    	if(dialStatus==0) {
    		dialStatusString="拨号失败";
    	}else if(dialStatus==1) {
    		dialStatusString="拨号成功";
    	}
    	json.put("chatDialingStatus", String.valueOf(dialStatus));
    	
    	fillData+="<div>===>拨号状态："+dialStatusString+"</div>";
    	
    	fillData+="<div>===>IP地址："+ip1+"."+ip2+"."+ip3+"."+ip4+"</div>";
    	
    	
    	try {
    		if(data.length>41) {
        		int versionLong = Integer.parseInt(FrameUtil.bytesToHexString(new byte[] {data[41]}), 16);
    	    	byte[] version=new byte[versionLong];
    	    	for(int i=0;i<versionLong;i++) {
    	    		version[i]=data[i+42];
    	    	}
    	    	String versionString = FrameUtil.AsciiToString(version);
    	    	
    	    	fillData+="<div>===>模块软件版本号长度："+versionLong+"</div><div>===>模块软件版本号："+versionString+"</div>";
        	}
		} catch (Exception e) {
			e.printStackTrace();
		}
    	
    	return fillData+";测试成功";
	}
    
    public static String dealOrder_07(byte[] data,JSONObject map,JSONObject json) throws Exception {
    	commonSuccessCheck(data);
    	String fillData="";
    	int linkStatus = Integer.parseInt(FrameUtil.bytesToHexString(new byte[] {data[1]}), 16);
    	json.put("wifiLinkStatus", String.valueOf(linkStatus));
    	int signal = Integer.parseInt(FrameUtil.bytesToHexString(new byte[] {data[2]}), 16);
    	String[] split = map.getString("value").split("#");
    	int min=Integer.parseInt(split[0]);
    	if(split.length==2) {
    		int max=Integer.parseInt(split[1]);
    		if(min>signal||max<signal) {
    			throw new Exception("信号强度不符合，设备："+signal+"，配置范围："+min+"~"+max+";测试失败");
    		}else {
    			json.put("wifiSignal", String.valueOf(signal));
    		}
    	}else if(split.length==1){
			if(signal<min) {
				throw new Exception("信号强度不符合，设备："+signal+"，配置范围：>"+min+";测试失败");
			}else {
				json.put("wifiSignal", String.valueOf(signal));
			}
		}else {
			throw new Exception("数据出错;测试失败");
		}
    	byte[] ip=new byte[4];
    	for(int i=0;i<4;i++) {
    		ip[i]=data[i+3];
    	}
    	int ip1 =Integer.parseInt(FrameUtil.bytesToHexString(new byte[] {ip[0]}),16);
    	int ip2 =Integer.parseInt(FrameUtil.bytesToHexString(new byte[] {ip[1]}),16);
    	int ip3 =Integer.parseInt(FrameUtil.bytesToHexString(new byte[] {ip[2]}),16);
    	int ip4 =Integer.parseInt(FrameUtil.bytesToHexString(new byte[] {ip[3]}),16);
    	byte[] mac=new byte[6];
    	int indexDo=7;
    	if(data.length==14) {
    		indexDo=8;
    	}
    	for(int i=0;i<6;i++) {
    		mac[i]=data[i+indexDo];
    	}
    	String macString = FrameUtil.bytesToHexString(mac);
    	String linkStatuString="";
    	if(linkStatus==0) {
    		linkStatuString="连接状态：未连接";
    	}else {
    		linkStatuString="连接状态：连接成功";
    	}
    	String signalString="信号强度："+signal;
    	String wifiIpString="WIFI IP地址："+ip1+"."+ip2+"."+ip3+"."+ip4;
    	json.put("wifiIp", ip1+"."+ip2+"."+ip3+"."+ip4);
    	String wifiMACString="WIFI mac地址:"+macString;
    	json.put("wifiMac", macString);
    	fillData=linkStatuString+";"+signalString+";"+wifiIpString+";"+wifiMACString;
    	return fillData;
	}
    
    public static String dealOrder_08(byte[] data,JSONObject map,JSONObject json) throws Exception {
    	commonSuccessCheck(data);
    	String fillData="";
    	int linkStatus = Integer.parseInt(FrameUtil.bytesToHexString(new byte[] {data[1]}), 16);
    	if(linkStatus==0) {
    		throw new Exception("连接状态：未连接;测试失败！");
    	}else {
    		json.put("gpsLinkStatus", String.valueOf(linkStatus));
    	}
    	int modelType = Integer.parseInt(FrameUtil.bytesToHexString(new byte[] {data[2]}), 16);
    	String gpsModelType = map.getString("gpsModelType");
    	json.put("gpsModelType", gpsModelType);
//    	if(!gpsModelType.equals(String.valueOf(modelType))) {
//    		throw new Exception("连接状态：连接成功;模块类型不匹配;测试失败");
//    	}else {
//    		json.put("gpsModelType", gpsModelType);
//    	}
    	byte[] longitude=new byte[6];
    	for(int i=0;i<6;i++) {
    		longitude[i]=data[i+3];
    	}
    	int longitude1 = Integer.parseInt(FrameUtil.bytesToHexString(new byte[] {longitude[0]}), 16);
    	int longitude2 = Integer.parseInt(FrameUtil.bytesToHexString(new byte[] {longitude[1]}), 16);
    	long longitude3 = Long.parseLong(FrameUtil.bytesToHexString(new byte[] {longitude[2],longitude[3],longitude[4],longitude[5],}), 16);
    	double parseLong = Double.parseDouble(longitude1+""+longitude2+"."+longitude3);
    	String[] split = map.getString("gpsLongitude").split("#");
    	double min=Double.parseDouble(split[0]);
    	double max=Double.parseDouble(split[1]);
    	if(min>parseLong||max<parseLong) {
    		fillData="经度不符合范围,配置经度："+min+"~"+max+",设备经度："+parseLong;
    		throw new Exception(fillData);
    	}else {
    		json.put("gpsLongitude",String.valueOf(parseLong));
    	}
    	byte[] Latitude=new byte[6];
    	for(int i=0;i<6;i++) {
    		Latitude[i]=data[i+9];
    	}
    	int Latitude1 = Integer.parseInt(FrameUtil.bytesToHexString(new byte[] {Latitude[0]}), 16);
    	int Latitude2 = Integer.parseInt(FrameUtil.bytesToHexString(new byte[] {Latitude[1]}), 16);
    	long Latitude3 = Long.parseLong(FrameUtil.bytesToHexString(new byte[] {Latitude[2],Latitude[3],Latitude[4],Latitude[5],}), 16);
    	double parseLat = Double.parseDouble(Latitude1+""+Latitude2+"."+Latitude3);
    	String[] split1 = map.getString("gpsLatitude").split("#");
    	double min1=Double.parseDouble(split1[0]);
    	double max1=Double.parseDouble(split1[1]);
    	if(min1>parseLat||max1<parseLat) {
    		fillData="纬度不符合范围,配置经度："+min1+"~"+max1+",设备纬度："+parseLat;
    		throw new Exception(fillData);
    	}else {
    		json.put("gpsLatitude",String.valueOf(parseLat));
    	}
    	
    	int sum = Integer.parseInt(FrameUtil.bytesToHexString(new byte[] {data[15]}), 16);
    	Integer gpsSum = Integer.parseInt(map.getString("gpsSum"));
    	if(gpsSum>sum) {
    		fillData="卫星数不正确，配置卫星数："+gpsSum+"，设备卫星数："+sum;
    		throw new Exception(fillData);
    	}else {
    		json.put("gpsSatellite",String.valueOf(sum));
    	}
    	
    	fillData="===>连接状态：连接成功;卫星数===>模块类型："+getGpsModelType(modelType)+";===>卫星数："+sum+";===>经度："+longitude1+
        		longitude2+"."+longitude3+";===>纬度："+Latitude1+Latitude2+"."+Latitude3+";测试成功";
    	
    	String ipString="";
    	if(data.length>=19) {
    		byte[] ip=new byte[4];
	        for(int i=0;i<4;i++) {
	        		ip[i]=data[i+16];
	        }
	        int ip1 =Integer.parseInt(FrameUtil.bytesToHexString(new byte[] {ip[0]}),16);
	        int ip2 =Integer.parseInt(FrameUtil.bytesToHexString(new byte[] {ip[1]}),16);
	        int ip3 =Integer.parseInt(FrameUtil.bytesToHexString(new byte[] {ip[2]}),16);
	        int ip4 =Integer.parseInt(FrameUtil.bytesToHexString(new byte[] {ip[3]}),16);
	        ipString=ip1+"."+ip2+"."+ip3+"."+ip4;
	        json.put("gpsIp", ipString);
	        ipString="===>有线IP地址："+ipString;
	        fillData="===>连接状态：连接成功;===>模块类型："+getGpsModelType(modelType)+";===>卫星数："+sum+";===>经度："+longitude1+
	        		longitude2+"."+longitude3+";===>纬度："+Latitude1+Latitude2+"."+Latitude3+";"+ipString+";测试成功";
    	}
    	
    	return fillData;
	}
    
    
    /**
     * 参数导入、导出、恢复出厂设置通用
     * @param data
     * @return
     * @throws Exception
     */
    public static String dealOrder_09(byte[] data) throws Exception {
		commonSuccessCheck(data);
		return "操作成功";
	}
    
    public static String dealOrder_0C(byte[] data,JSONObject json) throws Exception{
    	commonSuccessCheck(data);
    	String fillData="";
    	String statusString="";
    	int status=Integer.parseInt(FrameUtil.bytesToHexString(new byte[] {data[1]}), 16);
    	if(status==0) {
    		statusString="===>温度状态:RTC芯片温度";
    	}else if(status==1){
    		statusString="===>温度状态:硬盘温度";
    	}
    	json.put("temperatureStatus",String.valueOf(status));
    	String nuitString="";
    	int nuit=Integer.parseInt(FrameUtil.bytesToHexString(new byte[] {data[2]}), 16);
    	if(nuit==0) {
    		nuitString="===>温度单位:CELSIUS";
    	}else if(nuit==1){
    		nuitString="===>温度单位:FAHENHEIT";
    	}
    	json.put("temperatureUnit",String.valueOf(nuit));
    	long integer=Long.parseLong(FrameUtil.bytesToHexString(new byte[] {data[3],data[4]}), 16);
    	long decimal=Long.parseLong(FrameUtil.bytesToHexString(new byte[] {data[5],data[6]}),16);
    	String tempString=integer+"."+decimal;
    	json.put("temperatureValue",tempString);
    	fillData=statusString+";"+nuitString+";===>温度值:"+tempString+";测试成功";
    	return fillData;
	}
    
    public static String dealOrder_13(byte[] data)throws Exception {
    	commonSuccessCheck(data);
		String fillData="配置成功";
		
		return fillData;
	}
    
    public static String dealOrder_14(byte[] data,JSONObject json)throws Exception {
    	commonSuccessCheck(data);
    	String fillData="";
    	byte[] dataByte=new byte[data.length-1];
    	for (int i = 0; i < dataByte.length; i++) {
			dataByte[i]=data[i+1];
		}
    	String chip = FrameUtil.AsciiToString(dataByte);
    	json.put("chipNumber",chip);
    	fillData="===>获取数据："+chip+";测试成功";
    	return fillData;
    }
    
    public static String dealOrder_15(byte[] data)throws Exception {
    	commonSuccessCheck(data);
    	String fillData="";
    	byte[] dataByte=new byte[data.length-1];
    	for (int i = 0; i < dataByte.length; i++) {
			dataByte[i]=data[i+1];
		}
    	fillData="===>获取数据："+FrameUtil.bytesToHexString(dataByte)+";测试成功";
    	return fillData;
    }
    
    /**
     * 命令25，写入产品sn
     * @param data
     * @return
     * @throws Exception
     */
    public static String dealOrder_25(byte[] data,JSONObject json)throws Exception{
    	commonSuccessCheck(data);
    	byte[] dataByte=new byte[data.length-1];
    	for (int i = 0; i < dataByte.length; i++) {
			dataByte[i]=data[i+1];
		}
    	String fillData="SN："+json.getString("sn")+",写入成功";
    	return fillData;
	}
    /*
     * 设备子机型输入并对比
     */
    public static String dealOrder_26(byte[] data,JSONObject map,JSONObject json)throws Exception{
    	commonSuccessCheck(data);
    	String value = map.getString("value");
    	byte[] data1=new byte[] {data[1]};
    	String fillData ="";
    	String value1=FrameUtil.bytesToHexString(data1); 
    	Integer parseInt = Integer.parseInt(value1,16);
    	Integer parseInt2 = Integer.parseInt(value);
    	if(parseInt==parseInt2){
    		fillData="====>设备子机型："+parseInt+"；输入数据："+parseInt2+";测试成功";
    		json.put("childMachineType", String.valueOf(parseInt));
    	}else {
    		fillData="====>设备子机型："+parseInt+"；输入数据："+parseInt2+";结果错误";
    		throw new Exception(fillData);
    	}
    	return fillData;
	}
    
    public static String dealOrder_27(byte[] data,JSONObject json)throws Exception{
    	String terminalId = json.getString("terminalId");
    	commonSuccessCheck(data);
    	return "终端ID"+terminalId+",写入成功";
	}
    public static String dealOrder_1C(byte[] data,JSONObject json)throws Exception{
    	String phoneNumber = json.getString("phoneNumber");
    	commonSuccessCheck(data);
    	return "手机号："+phoneNumber+",写入成功";
	}
    
    //通用检测方法，看数据第一个字节 ，01表示成功，00表示失败
    private static void commonSuccessCheck(byte[] data) throws Exception {
    	if(data[0]==0x00) {
    		throw new Exception("操作失败！");
    	}else if(data[0]==0x01) {
    		return;
    	}else {
    		throw new Exception("数据出错！");
		}
    }
    
    public static String getChatModelType(int modelType) {
    	String modelTypeString="";
    	if(modelType==0){
    		modelTypeString="未知";
    	}else if(modelType==1) {
    		modelTypeString="GPRS";
    	}else if(modelType==2) {
    		modelTypeString="CDMA";
    	}else if(modelType==3) {
    		modelTypeString="EVDO";
    	}else if(modelType==4) {
    		modelTypeString="WCDMA";
    	}else if(modelType==5) {
    		modelTypeString="EDGE";
    	}else if(modelType==6) {
    		modelTypeString="TDSCDMA";
    	}else if(modelType==7) {
    		modelTypeString="LTE";
    	}else if(modelType==8) {
    		modelTypeString="LTE";
    	}else if(modelType==9) {
    		modelTypeString="5G";
    	}else if(modelType==10) {
    		modelTypeString="5G";
    	}
    	return modelTypeString;
    }

   
    /*
     * 通过命令获取取中文名，输出到前端
     */
    public static String getNameByOrder(String item) {
        String orderString = StringUtils.lowerCase(item);
        String order = "";
        
        switch (orderString) {
        case "order_01":
			order="时间校验";
			break;
		case "order_02":
			order="版本信息";
			break;
		case "order_03":
			order="MAC地址获取";
			break;
		case "order_04":
			order="MAC地址写入";
			break;
		case "order_05":
			order="存储器信息获取";
			break;
		case "order_06":
			order="通信模块信息获取";
			break;
		case "order_07":
			order="WIFI信息获取";
			break;
		case "order_08":
			order="GPS信息获取";
			break;
		case "order_09":
			order="参数导出";
			break;
		case "order_0a":
			order="参数导入";
			break;
		case "order_0b":
			order="恢复出厂（DSM）";
			break;
		case "order_0c":
			order="机内温度获取";
			break;
		case "order_0d":
			order="机型配置";
			break;
		case "order_0e":
			order="加密芯片号获取";
			break;
		case "order_0f":
			order="检测区域版本（战略低端机）";
			break;
		case "order_10":
			order="导入区域信息（战略低端机）";
			break;
		case "order_11":
			order="二维码信息获取";
			break;
		case "order_12":
			order="通信模块信息获取";
			break;
		case "order_13":
			order="设置时间（DSM）";
			break;
		case "order_14":
			order="格式化";
			break;
		case "order_15":
			order="ACC状态查询（DSM）";
			break;
		case "order_16":
			order="电压查询(外部电压，电池电压，法拉电容电压)（DSM）";
			break;
		case "order_17":
			order="重启设备（DSM）";
			break;
		case "order_18":
			order="声音环出";
			break;
		case "order_19":
			order="手机号写入";
			break;
		case "order_1a":
			order="传感器输入状态获取（DSM）";
			break;
		case "order_1b":
			order="控制传感器输出（DSM）";
			break;
		case "order_1c":
			order="手机号";
			break;
		case "order_1d":
			order="奥瞳算法licence鉴别结果广播";
			break;
		case "order_1e":
			order="获取奥瞳算法licence鉴别结果";
			break;
		case "order_1f":
			order="串口测试 （AIBOX）";
			break;
		case "order_20":
			order="六轴测试 （AIBOX）";
			break;
		case "order_21":
			order="脉冲测试 （AIBOX）";
			break;
		case "order_22":
			order="硬盘锁状态获取 （AIBOX）";
			break;
		case "order_23":
			order="CAN1 口测试 （AIBOX）";
			break;
		case "order_24":
			order="CAN2 口测试 （AIBOX）";
			break;
		case "order_25":
			order="产品SN写入";
			break;
		case "order_26":
			order="查询设备子机型";
			break;
		case "order_27":
			order="终端ID";
			break;
		case "order_40":
			order="工装与MDVR通信";
			break;
		case "order_41":
			order="音频校验（pc——工装） ";
			break;
		case "order_42":
			order="通道测试（pc——工装）";
			break;
		case "order_2b":
			order="TTS状态";
			break;
		case "order_clear":
			order="清空数据";
			break;
		case "order_card":
			order="刷卡模块类型";
			break;
		case "order_termin":
			order="终端号";
			break;
		case "order_bluetooth":
			order="蓝牙校验";
			break;
		case "order_producerid_old":
			order="制造商ID写入";
			break;
		case "order_terminalno_old":
			order="终端型号写入";
			break;
		case "order_producerid_new":
			order="制造商ID写入";
			break;
		case "order_terminalid_new":
			order="终端ID写入";
			break;
		case "order_terminalphone_new":
			order="终端手机号写入";
			break;
		case "order_terminalno_new":
			order="终端型号写入";
			break;
		default:
			break;
        } 
        return order;
      }
    
    public static String getYesOrNo(String code) {
		if("Y".equals(code)) {
			return "是";
		}else {
			return "否";
		}
	}
}
